Problem/Motivation

Drupal\Tests\system\Functional\System\CronRunTest

fail: [Other] Line 0 of sites/default/files/simpletest/phpunit-1102.xml:
PHPUnit Test failed to complete; Error: PHPUnit 9.6.8 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\system\Functional\System\CronRunTest
.F...                                                               5 / 5 (100%)

Time: 00:24.576, Memory: 4.00 MB

There was 1 failure:

1) Drupal\Tests\system\Functional\System\CronRunTest::testAutomatedCron
Failed asserting that 1691657672 is less than 1691657672.

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/var/www/html/core/modules/system/tests/src/Functional/System/CronRunTest.php:82
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>

I've seen it a few more times in the week or so than the two listed below
https://www.drupal.org/pift-ci-job/2737315
https://www.drupal.org/pift-ci-job/2734245

Proposed resolution

I _think_ in #4 I proved there's a race condition between the admin_user login triggering cron and updating its state, and this test doing the same thing.

I'm _sure_ using the \Drupal\Tests\WaitTerminateTestTrait solves whatever was wrong, see #5.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3380433

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

quietone created an issue. See original summary.

spokje’s picture

Assigned: Unassigned » spokje
StatusFileSize
new6.61 KB

Let's first see if this is reproducible with a patch that runs \Drupal\Tests\system\Functional\System\CronRunTest::testAutomatedCron, and only that, 7500 times.

spokje’s picture

StatusFileSize
new8.8 KB
spokje’s picture

I think the patch in #3 with output like

1) Drupal\Tests\system\Functional\System\CronRunTest::testAutomatedCron
|| 1:10800 || 2:10800 || 3:10800 || 4:10800 || 5:10800 || 6:10800||| | 1:10800 | 2:100
Failed asserting that 10800 is identical to 100.

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/IsIdentical.php:79
/var/www/html/core/modules/system/tests/src/Functional/System/CronRunTest.php:55
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

proves that, although the config automated_cron.settings.interval is set to 100, at the moment of checking it in \Drupal\automated_cron\EventSubscriber\AutomatedCron::onTerminate it sometime is still the default 10800.

The only reason I can think of why this would be happening is a race conditionsbetween the admin_user login triggering cron and updating its state, and this test doing the same thing.

spokje’s picture

StatusFileSize
new6.74 KB
new6.61 KB

Let's see if using \Drupal\Tests\WaitTerminateTestTrait::setWaitForTerminate can help us out here.

Patch using that Trait and running \Drupal\Tests\system\Functional\System\CronRunTest::testAutomatedCron, and only that, 7500 times attached together with the original 7500 patch from #2.

spokje’s picture

6 * 7500 = 45.000 failure free runs vs 7 failures in a non-patched 7500 run is good enough for me.

The actual patch will be in the MR.

spokje’s picture

Assigned: spokje » Unassigned
Issue summary: View changes
Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

6 * 7500 = 45.000 failure free runs vs 7 failures in a non-patched 7500 run is good enough for me.

Wooo!

longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed eaca861 and pushed to 11.x. Thanks!

  • longwave committed eaca861b on 11.x
    Issue #3380433 by Spokje, quietone: [random test failure] CronRunTest::...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.