From cebe64e0366639570cf671decf94b8149d7555b7 Mon Sep 17 00:00:00 2001
From: catch <6915-catch@users.noreply.drupalcode.org>
Date: Mon, 3 Feb 2025 15:13:22 +0000
Subject: [PATCH] Issue #3379560 by berdir, nlisgo, smustgrave: Random test
 failure in CronRunTest::testCronUI: The text "Last run: never" was not found

---
 .../system/tests/src/Functional/System/CronRunTest.php       | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/core/modules/system/tests/src/Functional/System/CronRunTest.php b/core/modules/system/tests/src/Functional/System/CronRunTest.php
index 47ed4f788cbb..2eb553021243 100644
--- a/core/modules/system/tests/src/Functional/System/CronRunTest.php
+++ b/core/modules/system/tests/src/Functional/System/CronRunTest.php
@@ -118,6 +118,11 @@ public function testCronExceptions(): void {
    * Make sure the cron UI reads from the state storage.
    */
   public function testCronUI(): void {
+    // 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();
+
     $admin_user = $this->drupalCreateUser(['administer site configuration']);
     $this->drupalLogin($admin_user);
     \Drupal::state()->delete('system.cron_last');
-- 
GitLab