From eaca861b386bda492ed1367035210cdd80000a4d Mon Sep 17 00:00:00 2001 From: Dave Long Date: Thu, 17 Aug 2023 14:27:44 +0100 Subject: [PATCH] Issue #3380433 by Spokje, quietone: [random test failure] CronRunTest::testAutomatedCron --- .../system/tests/src/Functional/System/CronRunTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/modules/system/tests/src/Functional/System/CronRunTest.php b/core/modules/system/tests/src/Functional/System/CronRunTest.php index 95d2611e67d..db7f15ee1a8 100644 --- a/core/modules/system/tests/src/Functional/System/CronRunTest.php +++ b/core/modules/system/tests/src/Functional/System/CronRunTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\system\Functional\System; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\Traits\Core\CronRunTrait; +use Drupal\Tests\WaitTerminateTestTrait; /** * Tests cron runs. @@ -13,6 +14,7 @@ use Drupal\Tests\Traits\Core\CronRunTrait; class CronRunTest extends BrowserTestBase { use CronRunTrait; + use WaitTerminateTestTrait; /** * Modules to enable. @@ -56,7 +58,12 @@ class CronRunTest extends BrowserTestBase { * need the exact time when cron is triggered. */ public function testAutomatedCron() { - // Test with a logged in user; anonymous users likely don't cause Drupal to + // To prevent race conditions between the admin_user login triggering cron + // and updating its state, and this test doing the same thing, we use + // \Drupal\Tests\WaitTerminateTestTrait::setWaitForTerminate. + $this->setWaitForTerminate(); + + // Test with a logged-in user; anonymous users likely don't cause Drupal to // fully bootstrap, because of the internal page cache or an external // reverse proxy. Reuse this user for disabling cron later in the test. $admin_user = $this->drupalCreateUser(['administer site configuration']);