Problem/Motivation
https://www.drupal.org/pift-ci-job/866534
https://www.drupal.org/pift-ci-job/991286
1) Drupal\Tests\comment\Functional\CommentStatisticsTest::testCommentNodeCommentStatistics
The value of node last_comment_name is the name of the anonymous user.
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'hFpV0qnB'
+''
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:96
/var/www/html/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php:121
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
https://www.drupal.org/pift-ci-job/2692252
Steps to reproduce
The fact that this one didn't occur for a long time immediately points to a timing issue.
We went to faster test instances (and it dissappeared) and after that we're on slower instances now.
I dabbled with this one for quite a while and can't really pin down _where_ the timing issue occurs.
Somewhere else, I dumped the node comment list when the test fails.
The relevant bit:
#list: array:1 [
0 => Drupal\comment\Plugin\Field\FieldType\CommentItem {#4072
#definition: Drupal\Core\Field\TypedData\FieldItemDataDefinition {#4911}
#name: 0
#parent: Drupal\comment\CommentFieldItemList {#7857}
#_serviceIds: []
#_entityStorages: []
#stringTranslation: null
#typedDataManager: Drupal\Core\TypedData\TypedDataManager {#5039}
#values: array:6 [
"status" => "2"
"cid" => "1"
"last_comment_timestamp" => "1687262036"
"last_comment_name" => ""
"last_comment_uid" => "4"
"comment_count" => "2"
]
#properties: []
}
]
So somehow when it goes wrong, the last comment is tributed to uid 4, which is $this->webUser2 in the test.
Asserting that that user, which logs in to make the first comment and then logs out, is not still logged in always passes, so the timing issue lays elsewhere.
Deleting caches also didn't help.
Proposed resolution
We're testing a rare occurence where a user logs in, makes a comment, logs out, comment settings are changed, logged out user makes a comment, comment settings are changed again and the same anon-user comments again.
These setting changes are done directly using user_role_change_permissions.
I found that actually logging in, and change the permissions using "/admin/people/permissions" doesn't fail randomly.
If this is because of the extra delay that this causes or something else is a mystery to me.
Remaining tasks
Looking at this test, there's nothing in it that actually uses asserts against the actual forms/screens/whatever.
It solely tests (posted) comments and the node they belong to.
Therefore, IMHO this should be a Kernel test.
I would like some confirmation on that, and if it should be, open a follow-up for that.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 2980750-16.patch | 2.52 KB | spokje |
Comments
Comment #2
tacituseu commentedComment #6
krzysztof domańskiWrong patch. Ignore.
Comment #7
krzysztof domańskiComment #8
krzysztof domańskiIMO out of date.
Comment #9
xjmComment #10
spokjeBack with a vengeance: https://www.drupal.org/pift-ci-job/2692252
Comment #11
spokjeComment #12
spokjeLet's first proof that running
\Drupal\Tests\comment\Functional\CommentStatisticsTestand\Drupal\Tests\comment\Functional\CommentStatisticsTestalone produces the random test failure.Here's a patch that runs only
\Drupal\Tests\comment\Functional\CommentStatisticsTest1500 times.Comment #13
spokjeHmm, this issue _is_ old...
Comment #14
spokjeThe normal routine to prove a random failure is fixed is to run the failing patch and the patch with the fix at the same time, whilst the latter has to have ~8000 - 10.000 failure free runs to prove it's credibility.
Let's do that here.
Comment #15
spokjeThat's 6 * 5000 = 30.000 failure free runs.
Good enough for me, here's the actual patch.
Comment #16
spokjeMeh! Retry.
Comment #17
spokjeComment #18
spokjeComment #19
spokjeHmm, editing this in 2 tabs appareantly ate the visibility of patch #16 and I don't see it in the file list to restore that visibility.
Re-upping
Comment #20
spokjeComment #21
smustgrave commentedLGTM
Comment #24
catchWould normally push back against changing admin settings in the UI (unless that's what we're testing), but given how long this has been random, let's make it not random again and any refactoring can happen on a firmer footing.
Committed/pushed to 11.x and cherry-picked to 10.1.x, thanks!