deprecate CronRunTrait

Created on 12 April 2022, over 2 years ago
Updated 12 July 2024, 3 months ago

Problem/Motivation

CronRunTrait provides a method which does this to run cron:

    $this->drupalGet('cron/' . \Drupal::state()->get('system.cron_key'));

It's inefficient to run cron in a test by making an HTTP request.

Only the test that is actually covering the '/cron' route should be making requests to it. Anything else that is testing its own hook_cron code should be running cron by calling the cron service.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
PHPUnitย  โ†’

Last updated 1 day ago

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany donquixote

    This might be true.
    But I actually had an example where visiting /cron had a different effect than calling $cron->run() from the service.

    Surely there is a module somewhere that is doing things wrong, e.g. not reset a cache variable etc.
    I have not figured it out yet.
    But in a functional test we want to be realistic.
    So we want at least to keep the option to run cron as a separate request.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany donquixote
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia onkararun

    Arun.k โ†’ made their first commit to this issueโ€™s fork.

  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia onkararun
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Vishal Choudhary Dharmshala

    @arun.k I have Tested Your branch 3274813-deprecate-cronruntrait
    The deprecated code was removed from this File
    like
    Filename:
    Db_LogTest.php
    CronRunTrait.php

    Remove code:
    Before:
    $cron_count = $this->runCron();

    After:
    $cron_count = \Drupal::service('cron')->run();

    I Think We Will need to move RTBC

    Thanks For Contribution.

  • Status changed to RTBC 3 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Vishal Choudhary Dharmshala
  • Status changed to Needs work 3 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    CronRunTrait has the cronRun method, here we have only changed the runCron method which is different. There is no open MR and so the tests haven't even run yet.

Production build 0.71.5 2024