Test site may be destroyed while an (automated) cron is still running

Created on 11 August 2025, about 10 hours ago

Problem/Motivation

If a functional test installs the Automated Cron module and then performs some requests against those test sites, any of those requests may lead to cron being run. Since this happens outside of the actual test flow, cron may still not be completed when the test has completed and the test site is being torn down. This will then lead to database exceptions of the cron jobs because database tables they expect to exist no longer do.

Steps to reproduce

Create a test that installs Umami (as that includes Automated Cron and Search) and only performs a single request and then finishes. Run that test on SQLite (not sure why that is required to reproduce this, but it seems to be) and be surprised that you will get, for example, the following exception:

Failed to log error: Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 1 no such table: test66738342.watchdog: INSERT INTO "test66738342"."watchdog" ("uid", "type", "message", "variables", "severity", "link", "location", "referer", "hostname", "timestamp") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?); Array
(
[0] => 0
[1] => cron
[2] => %type: @message in %function (line %line of %file).
[3] => a:6:{s:5:"%type";s:44:"Drupal\search\Exception\SearchIndexException";s:8:"@message";s:40:"Failed to update totals for index words.";s:9:"%function";s:46:"Drupal\search\SearchIndex->updateWordWeights()";s:5:"%file";s:74:".../core/modules/search/src/SearchIndex.php";s:5:"%line";i:292;s:17:"@backtrace_string";s:2705:"#0 .../core/modules/help/src/Plugin/Search/HelpSearch.php(372): Drupal\search\SearchIndex->updateWordWeights(Array)

Note that I was not able to reproduce this locally, thus far, but this Config Overlay CI job shows the problem.

Proposed resolution

Explicitly wait for cron to finish before tearing down the test site. (If you have any more elegant solutions for this, please share, I couldn't come up with anything...)

Remaining tasks

User interface changes

-

Introduced terminology

-

API changes

-

Data model changes

-

Release notes snippet

-

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

phpunit

Created by

🇩🇪Germany tstoeckler Essen, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024