From 5a6734a31e18fb376dd68f986fc89e6a3e05d4cf Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Fri, 4 Aug 2023 14:17:08 -0500 Subject: [PATCH] AC-9270: Add Optional --force-use-same-process Parameter to Cron:Run Cli Command --- .../Module/MagentoWebDriver.php | 79 +------------------ 1 file changed, 2 insertions(+), 77 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index f2580deaf..3b4d988c2 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -57,7 +57,6 @@ class MagentoWebDriver extends WebDriver pause as codeceptPause; } - const MAGENTO_CRON_INTERVAL = 60; const MAGENTO_CRON_COMMAND = 'cron:run'; /** @@ -118,13 +117,6 @@ class MagentoWebDriver extends WebDriver */ private $jsErrors = []; - /** - * Contains last execution times for Cron - * - * @var int[] - */ - private $cronExecution = []; - /** * Sanitizes config, then initializes using parent. * @@ -584,65 +576,6 @@ public function magentoCron($cronGroups = null, $timeout = null, $arguments = nu return $this->executeCronjobs($cronGroups, $timeout, $arguments); } - /** - * Updates last execution time for Cron - * - * @param array $cronGroups - * @return void - */ - private function notifyCronFinished(array $cronGroups = []) - { - if (empty($cronGroups)) { - $this->cronExecution['*'] = time(); - } - - foreach ($cronGroups as $group) { - $this->cronExecution[$group] = time(); - } - } - - /** - * Returns last Cron execution time for specific cron or all crons - * - * @param array $cronGroups - * @return integer - */ - private function getLastCronExecution(array $cronGroups = []) - { - if (empty($this->cronExecution)) { - return 0; - } - - if (empty($cronGroups)) { - return (int)max($this->cronExecution); - } - - $cronGroups = array_merge($cronGroups, ['*']); - - return array_reduce($cronGroups, function ($lastExecution, $group) { - if (isset($this->cronExecution[$group]) && $this->cronExecution[$group] > $lastExecution) { - $lastExecution = $this->cronExecution[$group]; - } - - return (int)$lastExecution; - }, 0); - } - - /** - * Returns time to wait for next run - * - * @param array $cronGroups - * @param integer $cronInterval - * @return integer - */ - private function getCronWait(array $cronGroups = [], int $cronInterval = self::MAGENTO_CRON_INTERVAL) - { - $nextRun = $this->getLastCronExecution($cronGroups) + $cronInterval; - $toNextRun = $nextRun - time(); - - return max(0, $toNextRun); - } - /** * Runs DELETE request to delete a Magento entity against the url given. * @@ -1021,8 +954,6 @@ public function getOTP($secretsPath = null) } /** - * Waits proper amount of time to perform Cron execution - * * @param array $cronGroups * @param integer $timeout * @param string $arguments @@ -1037,11 +968,7 @@ private function executeCronjobs($cronGroups, $timeout, $arguments): string $arguments .= ' --bootstrap=standaloneProcessStarted=1'; } - $waitFor = $this->getCronWait($cronGroups); - - if ($waitFor) { - $this->wait($waitFor); - } + $arguments .= ' --force-use-same-process'; // Execute cron jobs in one process $command = array_reduce($cronGroups, function ($command, $cronGroup) { $command .= ' --group=' . $cronGroup; @@ -1051,9 +978,7 @@ private function executeCronjobs($cronGroups, $timeout, $arguments): string $cronResult = $this->magentoCLI($command, $timeout, $arguments); $timeEnd = microtime(true); - $this->notifyCronFinished($cronGroups); - - return sprintf('%s (wait: %ss, execution: %ss)', $cronResult, $waitFor, round($timeEnd - $timeStart, 2)); + return sprintf('%s (execution: %ss)', $cronResult, round($timeEnd - $timeStart, 2)); } /**