Skip to content
Snippets Groups Projects
Commit e910452a authored by catch's avatar catch
Browse files

Issue #1875020 by longwave, David_Rothstein, slip, alexpott, catch,...

Issue #1875020 by longwave, David_Rothstein, slip, alexpott, catch, smustgrave, jhodgdon: Cron queue gets processed every time cron is called, regardless of whether it's already being processed elsewhere

(cherry picked from commit d06dfb35)
parent eeafec56
No related branches found
No related tags found
11 merge requests!8506Draft: Issue #3456536 by ibrahim tameme,!5646Issue #3350972 by nod_: [random test failure]...,!5600Issue #3350972 by nod_: [random test failure]...,!5343Issue #3305066 by quietone, Rename RedirectLeadingSlashesSubscriber,!3603#ISSUE 3346218 Add a different message on edit comment,!3555Issue #2473873: Views entity operations lack cacheability support, resulting in incorrect dropbuttons,!3494Issue #3327018 by Spokje, longwave, xjm, mondrake: Update PHPStan to 1.9.3 and...,!3410Issue #3340128: UserLoginForm::submitForm has some dead code,!3389Issue #3325184 by Spokje, andypost, xjm, smustgrave: $this->configFactory is...,!3381Issue #3332363: Refactor Claro's menus-and-lists stylesheet,!3307Issue #3326193: CKEditor 5 can grow past the viewport when there is a lot of content
......@@ -134,6 +134,10 @@ public function run() {
}
else {
$this->invokeCronHandlers();
// Process cron queues.
$this->processQueues();
$this->setCronLastTime();
// Release cron lock.
......@@ -143,9 +147,6 @@ public function run() {
$return = TRUE;
}
// Process cron queues.
$this->processQueues();
// Restore the user.
$this->accountSwitcher->switchBack();
......
......@@ -2,6 +2,8 @@
namespace Drupal\Tests\Core;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Cron;
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Drupal\Core\Queue\DelayedRequeueException;
......@@ -64,14 +66,8 @@ protected function setUp(): void {
// Create a mock logger to set a flag in the resulting state.
$logger = $this->prophesize('Drupal\Core\Logger\LoggerChannelInterface');
// Safely ignore the cron re-run message when failing to acquire a lock.
//
// We don't need to run regular cron tasks, and we're still implicitly
// testing that queues are being processed.
//
// This argument will need to be updated to match the message text in
// Drupal\Core\Cron::run() should the original text ever be updated.
$logger->warning(Argument::exact('Attempting to re-run cron while it is already running.'))->shouldBeCalled();
// Safely ignore the cron success message.
$logger->info('Cron run completed.')->shouldBeCalled();
// Set a flag to track when a message is logged by adding a callback
// function for each logging method.
foreach (get_class_methods(LoggerInterface::class) as $logger_method) {
......@@ -87,11 +83,18 @@ protected function setUp(): void {
// Create a mock time service.
$time = $this->prophesize('Drupal\Component\Datetime\TimeInterface');
// Create a mock config factory and config object.
$config_factory = $this->prophesize(ConfigFactoryInterface::class);
$config = $this->prophesize(ImmutableConfig::class);
$config->get('logging')->willReturn(FALSE);
$config_factory->get('system.cron')->willReturn($config->reveal());
// Build the container using the resulting mock objects.
\Drupal::setContainer(new ContainerBuilder());
\Drupal::getContainer()->set('logger.factory', $logger_factory->reveal());
\Drupal::getContainer()->set('datetime.time', $time->reveal());
\Drupal::getContainer()->set('state', $this->state);
\Drupal::getContainer()->set('config.factory', $config_factory->reveal());
// Create mock objects for constructing the Cron class.
$module_handler = $this->prophesize('Drupal\Core\Extension\ModuleHandlerInterface');
......@@ -99,11 +102,9 @@ protected function setUp(): void {
$queue_worker_manager = $this->prophesize('Drupal\Core\Queue\QueueWorkerManagerInterface');
$state = $this->prophesize('Drupal\Core\State\StateInterface');
$account_switcher = $this->prophesize('Drupal\Core\Session\AccountSwitcherInterface');
// Create a lock that will always fail when attempting to acquire; we're
// only interested in testing ::processQueues(), not the other stuff.
$lock_backend = $this->prophesize('Drupal\Core\Lock\LockBackendInterface');
$lock_backend->acquire(Argument::exact('cron'), Argument::cetera())->willReturn(FALSE);
$lock_backend->acquire('cron', Argument::cetera())->willReturn(TRUE);
$lock_backend->release('cron')->shouldBeCalled();
// Create a queue worker definition for testing purposes.
$queue_worker = $this->randomMachineName();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment