From ed808ca038c4c2ca0da416efdfa8b644b80548ea Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Fri, 31 Jan 2025 22:24:35 +0100
Subject: [PATCH] add wait for terminate

---
 .../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