Problem/Motivation
Seen this several times recently, most recent: https://git.drupalcode.org/project/drupal/-/jobs/9726770
Automated Cron (Drupal\Tests\automated_cron\Functional\AutomatedCron)
✘ Runs cron on http request
┐
├ Failed asserting that 1778239032 is null.
│
│ /builds/core/modules/automated_cron/tests/src/Functional/AutomatedCronTest.php:42
┴
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3589156
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:
- 3589156-cron-random-test-failure
changes, plain diff MR !15711
Comments
Comment #2
longwaveThe failure is here:
I can only assume that the first page load of the functional test is still terminating, which includes running cron, and
AutomatedCron::onTerminate()writes the timestamp exactly between the delete and get?Maybe we should not install
automated_cronvia $modules but manually in the test, then we won't make any accidental HTTP requests that would cause the terminate event to fire? In fact, we might just be able to assert the null instead of setting it first?Comment #3
longwaveAlso took the liberty to fix up the @legacy-covers annotation while we're here.
Comment #5
catchThat looks great to me.
Comment #6
mstrelan commentedI can only assume that the first page load of the functional test is still terminatingWhat is the first http request? I didn't think there were any before this point in the test.
Comment #7
longwave@mstrelan
BrowserTestBase::setup()calls::initMink()which calls::initFrontPage()to visit the homepage so cookies can be set. So I guess if cron is installed already, it runs on the terminate event of this homepage load?Comment #8
longwavePerhaps instead of loading the homepage we could visit a known image URL or similar, which might be slightly more performant in some tests where we don't need to load the homepage at all? Out of scope for here though, unless we want to try that instead of the suggested fix.
Comment #9
longwaveOpened #3589236: Visit an image instead of the homepage in BrowserTestBase::initFrontPage()
Comment #10
mstrelan commentedThanks that makes sense
Comment #13
catchYeah this has to be exactly what's happening. I'd forgotten about the initial front page load for cookies but automated cron will definitely run on the first http request that gets made.
Going to go ahead and commit this even though I RTBCd it because @mstrelan's review ended up a +1. The change here is pretty minimal and we have a follow-up for the trickier bit.