From f5b149824746b998e459ae43953b8c72fb31414c Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Fri, 21 Oct 2022 11:06:05 +0100 Subject: [PATCH 1/5] Improve test coverage --- .../Indexer/Test/Unit/Model/Mview/View/StateTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php b/app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php index 2841a0415ae94..b1ba91f33feff 100644 --- a/app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php @@ -9,6 +9,7 @@ use Magento\Framework\Event\ManagerInterface; use Magento\Framework\Model\Context; +use Magento\Framework\Mview\View\StateInterface; use Magento\Framework\Registry; use Magento\Indexer\Model\Mview\View\State; use Magento\Indexer\Model\ResourceModel\Mview\View\State\Collection; @@ -158,4 +159,13 @@ public function testSetterAndGetterWithApplicationLock($setStatus, $getStatus, $ $this->model->setStatus($setStatus); $this->assertEquals($getStatus, $this->model->getStatus()); } + + public function testDefaultValues(): void + { + $this->assertEquals(StateInterface::MODE_DISABLED, $this->model->getMode()); + $this->assertEquals(StateInterface::STATUS_IDLE, $this->model->getStatus()); + $this->assertNull($this->model->getUpdated()); + $this->assertNull($this->model->getVersionId()); + $this->assertNull($this->model->getViewId()); + } } From 66ee4b5aec25f869a0998647c7b8f27804a029ca Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Fri, 21 Oct 2022 11:07:04 +0100 Subject: [PATCH 2/5] Set default indexer mode to 'schedule' --- app/code/Magento/Indexer/Model/Mview/View/State.php | 2 +- .../Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php | 2 +- app/code/Magento/Indexer/etc/db_schema.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Indexer/Model/Mview/View/State.php b/app/code/Magento/Indexer/Model/Mview/View/State.php index 66cc423f189c7..ed79de7a97934 100644 --- a/app/code/Magento/Indexer/Model/Mview/View/State.php +++ b/app/code/Magento/Indexer/Model/Mview/View/State.php @@ -69,7 +69,7 @@ public function __construct( \Magento\Framework\App\DeploymentConfig $configReader = null ) { if (!isset($data['mode'])) { - $data['mode'] = self::MODE_DISABLED; + $data['mode'] = self::MODE_ENABLED; } if (!isset($data['status'])) { $data['status'] = self::STATUS_IDLE; diff --git a/app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php b/app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php index b1ba91f33feff..5e227634a95a4 100644 --- a/app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php @@ -162,7 +162,7 @@ public function testSetterAndGetterWithApplicationLock($setStatus, $getStatus, $ public function testDefaultValues(): void { - $this->assertEquals(StateInterface::MODE_DISABLED, $this->model->getMode()); + $this->assertEquals(StateInterface::MODE_ENABLED, $this->model->getMode()); $this->assertEquals(StateInterface::STATUS_IDLE, $this->model->getStatus()); $this->assertNull($this->model->getUpdated()); $this->assertNull($this->model->getVersionId()); diff --git a/app/code/Magento/Indexer/etc/db_schema.xml b/app/code/Magento/Indexer/etc/db_schema.xml index e316e50f79e9a..b1434f3a79384 100644 --- a/app/code/Magento/Indexer/etc/db_schema.xml +++ b/app/code/Magento/Indexer/etc/db_schema.xml @@ -26,7 +26,7 @@ - + Date: Fri, 4 Nov 2022 12:23:31 +0000 Subject: [PATCH 3/5] Fix static code analysis test --- app/code/Magento/Indexer/Model/Mview/View/State.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Indexer/Model/Mview/View/State.php b/app/code/Magento/Indexer/Model/Mview/View/State.php index ed79de7a97934..b7b2c2f172dd6 100644 --- a/app/code/Magento/Indexer/Model/Mview/View/State.php +++ b/app/code/Magento/Indexer/Model/Mview/View/State.php @@ -150,8 +150,7 @@ public function getStatus() { $status = $this->getData('status'); if ($this->isUseApplicationLock()) { - if ( - $status == \Magento\Framework\Mview\View\StateInterface::STATUS_WORKING && + if ($status == \Magento\Framework\Mview\View\StateInterface::STATUS_WORKING && !$this->lockManager->isLocked($this->lockPrefix . $this->getViewId()) ) { return \Magento\Framework\Mview\View\StateInterface::STATUS_IDLE; From c7c271cdcae6416d10a53b4396910246771c77f7 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Mon, 13 Mar 2023 17:05:18 +0000 Subject: [PATCH 4/5] Fix integration tests --- .../config/post-install-setup-command-config.php.dist | 10 +++++++++- .../etc/post-install-setup-command-config.php.dist | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/config/post-install-setup-command-config.php.dist b/dev/tests/api-functional/config/post-install-setup-command-config.php.dist index aeb70513ed532..8e3a9b8faa7e5 100644 --- a/dev/tests/api-functional/config/post-install-setup-command-config.php.dist +++ b/dev/tests/api-functional/config/post-install-setup-command-config.php.dist @@ -15,6 +15,14 @@ return [ '--remote-storage-bucket' => 'myBucket', '--remote-storage-region' => 'us-east-1', ] - ] + ], */ + [ + // Indexers start in 'schedule' mode, but many of our tests assume that + // indexers are up to date. Because we don't run cron in our testsuite, + // we need to ensure that the indexers are up to date before we run our + // tests. + 'command' => 'indexer:reindex', + 'config' => [], + ], ]; diff --git a/dev/tests/integration/etc/post-install-setup-command-config.php.dist b/dev/tests/integration/etc/post-install-setup-command-config.php.dist index c2a0bdd2cb865..96eea45532bd4 100644 --- a/dev/tests/integration/etc/post-install-setup-command-config.php.dist +++ b/dev/tests/integration/etc/post-install-setup-command-config.php.dist @@ -19,6 +19,14 @@ return [ [ 'command' => 'setup:upgrade', 'config' => [] - ] + ], */ + [ + // Indexers start in 'schedule' mode, but many of our tests assume that + // indexers are up to date. Because we don't run cron in our testsuite, + // we need to ensure that the indexers are up to date before we run our + // tests. + 'command' => 'indexer:reindex', + 'config' => [], + ], ]; From acaabbc2f0257b98ba56f477336a5899e00f5f2b Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 10 Oct 2023 09:10:06 +0100 Subject: [PATCH 5/5] Revert "AC-6975::Set default indexer mode to schedule - Set Indexer Mode as Update by Schedule during Magento Installation" This reverts commit 1a5795ec7381572b2b456f099d3057f60636cdc3. --- .../TestFramework/WebApiApplication.php | 7 -- setup/src/Magento/Setup/Model/Installer.php | 36 --------- .../Setup/Test/Unit/Model/InstallerTest.php | 74 ++----------------- 3 files changed, 7 insertions(+), 110 deletions(-) diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php b/dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php index ce130d94f91ea..00d447bd53497 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php @@ -50,13 +50,6 @@ public function install($cleanup) } $this->_shell->execute($installCmd, $installArgs); } - /* Set Indexer mode as "Update on Save" & Reindex all the Indexers */ - $this->_shell->execute( - 'php -f ' . BP . '/bin/magento indexer:set-mode realtime -vvv' - ); - $this->_shell->execute( - 'php -f ' . BP . '/bin/magento indexer:reindex -vvv' - ); $this->runPostInstallCommands(); } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index fe4b4d4517a59..edcebe4c85f73 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -27,8 +27,6 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\RuntimeException; use Magento\Framework\Filesystem; -use Magento\Framework\Indexer\IndexerInterface; -use Magento\Framework\Indexer\IndexerRegistry; use Magento\Framework\Model\ResourceModel\Db\Context; use Magento\Framework\Module\ModuleList\Loader as ModuleLoader; use Magento\Framework\Module\ModuleListInterface; @@ -48,7 +46,6 @@ use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Validation\ValidationException; -use Magento\Indexer\Model\Indexer\Collection; use Magento\PageCache\Model\Cache\Type as PageCache; use Magento\RemoteStorage\Driver\DriverException; use Magento\Setup\Console\Command\InstallCommand; @@ -340,8 +337,6 @@ public function __construct( * @throws FileSystemException * @throws LocalizedException * @throws RuntimeException - * @SuppressWarnings(PHPMD.NPathComplexity) - * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function install($request) { @@ -379,9 +374,6 @@ public function install($request) $script[] = ['Disabling Maintenance Mode:', 'setMaintenanceMode', [0]]; $script[] = ['Post installation file permissions check...', 'checkApplicationFilePermissions', []]; $script[] = ['Write installation date...', 'writeInstallationDate', []]; - if (empty($request['magento-init-params'])) { - $script[] = ['Enabling Update by Schedule Indexer Mode...', 'setIndexerModeSchedule', []]; - } $estimatedModules = $this->createModulesConfig($request, true); $total = count($script) + 4 * count(array_filter($estimatedModules)); $this->progress = new Installer\Progress($total, 0); @@ -1846,32 +1838,4 @@ private function revertRemoteStorageConfiguration() $configData = [$remoteStorageData->getFileKey() => $remoteStorageData->getData()]; $this->deploymentConfigWriter->saveConfig($configData, true); } - - /** - * Set Index mode as 'Update by Schedule' - * - * @return void - * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback. - * @throws LocalizedException - * @throws \Exception - */ - private function setIndexerModeSchedule(): void - { - /** @var Collection $indexCollection */ - $indexCollection = $this->objectManagerProvider->get()->get(Collection::class); - $indexerIds = $indexCollection->getAllIds(); - try { - foreach ($indexerIds as $indexerId) { - /** @var IndexerInterface $model */ - $model = $this->objectManagerProvider->get()->get(IndexerRegistry::class) - ->get($indexerId); - $model->setScheduled(true); - } - $this->log->log(__('%1 indexer(s) are in "Update by Schedule" mode.', count($indexerIds))); - } catch (LocalizedException $e) { - $this->log->log($e->getMessage()); - } catch (\Exception $e) { - $this->log->log(__("We couldn't change indexer(s)' mode because of an error: ".$e->getMessage())); - } - } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index ea372851de1cc..8bb9a8da952a6 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -29,8 +29,6 @@ use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\Directory\WriteInterface; use Magento\Framework\Filesystem\DriverPool; - use Magento\Framework\Indexer\IndexerInterface; - use Magento\Framework\Indexer\IndexerRegistry; use Magento\Framework\Model\ResourceModel\Db\Context; use Magento\Framework\Module\ModuleList\Loader; use Magento\Framework\Module\ModuleListInterface; @@ -44,7 +42,6 @@ use Magento\Framework\Setup\SampleData\State; use Magento\Framework\Setup\SchemaListener; use Magento\Framework\Validation\ValidationException; - use Magento\Indexer\Model\Indexer\Collection; use Magento\RemoteStorage\Driver\DriverException; use Magento\RemoteStorage\Setup\ConfigOptionsList as RemoteStorageValidator; use Magento\Setup\Console\Command\InstallCommand; @@ -227,19 +224,6 @@ class InstallerTest extends TestCase */ private $patchApplierFactoryMock; - /** - * @var Collection|MockObject - */ - private $indexerMock; - /** - * @var IndexerRegistry|MockObject - */ - private $indexerRegistryMock; - /** - * @var IndexerInterface|MockObject - */ - private $indexerInterfaceMock; - /** * @inheritdoc */ @@ -279,10 +263,6 @@ protected function setUp(): void $this->patchApplierFactoryMock->expects($this->any())->method('create')->willReturn( $this->patchApplierMock ); - $this->indexerMock = $this->createMock(Collection::class); - $this->indexerRegistryMock = $this->createMock(IndexerRegistry::class); - $this->indexerInterfaceMock = $this->getMockForAbstractClass(IndexerInterface::class); - $this->object = $this->createObject(); } @@ -449,9 +429,7 @@ public function testInstall(array $request, array $logMessages) [DeclarationInstaller::class, $this->declarationInstallerMock], [Registry::class, $registry], [SearchConfig::class, $searchConfigMock], - [RemoteStorageValidator::class, $remoteStorageValidatorMock], - [Collection::class, $this->indexerMock], - [IndexerRegistry::class, $this->indexerRegistryMock] + [RemoteStorageValidator::class, $remoteStorageValidatorMock] ] ); $this->adminFactory->expects($this->any())->method('create')->willReturn( @@ -467,15 +445,6 @@ public function testInstall(array $request, array $logMessages) $this->filePermissions->expects($this->once()) ->method('getMissingWritableDirectoriesForDbUpgrade') ->willReturn([]); - $this->indexerMock->expects($this->once())->method('getAllIds')->willReturn( - [ - 'catalog_category_product', - 'catalog_product_category', - ] - ); - $this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn( - $this->indexerInterfaceMock - ); call_user_func_array( [ $this->logger->expects($this->exactly(count($logMessages)))->method('log'), @@ -538,8 +507,6 @@ public function installDataProvider() ['Disabling Maintenance Mode:'], ['Post installation file permissions check...'], ['Write installation date...'], - ['Enabling Update by Schedule Indexer Mode...'], - ['2 indexer(s) are in "Update by Schedule" mode.'], ['Sample Data is installed with errors. See log file for details'] ], ], @@ -593,8 +560,6 @@ public function installDataProvider() ['Disabling Maintenance Mode:'], ['Post installation file permissions check...'], ['Write installation date...'], - ['Enabling Update by Schedule Indexer Mode...'], - ['2 indexer(s) are in "Update by Schedule" mode.'], ['Sample Data is installed with errors. See log file for details'] ], ], @@ -733,20 +698,9 @@ public function testInstallWithOrderIncrementPrefix(array $request, array $logMe [DeclarationInstaller::class, $this->declarationInstallerMock], [Registry::class, $registry], [SearchConfig::class, $searchConfigMock], - [RemoteStorageValidator::class, $remoteStorageValidatorMock], - [Collection::class, $this->indexerMock], - [IndexerRegistry::class, $this->indexerRegistryMock] + [RemoteStorageValidator::class, $remoteStorageValidatorMock] ] ); - $this->indexerMock->expects($this->once())->method('getAllIds')->willReturn( - [ - 'catalog_category_product', - 'catalog_product_category', - ] - ); - $this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn( - $this->indexerInterfaceMock - ); $this->adminFactory->expects($this->any())->method('create')->willReturn( $this->createMock(AdminAccount::class) ); @@ -830,8 +784,6 @@ public function installWithOrderIncrementPrefixDataProvider(): array ['Disabling Maintenance Mode:'], ['Post installation file permissions check...'], ['Write installation date...'], - ['Enabling Update by Schedule Indexer Mode...'], - ['2 indexer(s) are in "Update by Schedule" mode.'], ['Sample Data is installed with errors. See log file for details'] ], ], @@ -1151,17 +1103,14 @@ public function testInstallWithUnresolvableRemoteStorageValidator() $objectManagerReturnMapSequence = [ 0 => [Registry::class, $registry], 1 => [DeclarationInstaller::class, $this->declarationInstallerMock], - 2 => [SearchConfig::class, $searchConfigMock], - 3 => [ + 3 => [SearchConfig::class, $searchConfigMock], + 4 => [ RemoteStorageValidator::class, new ReflectionException('Class ' . RemoteStorageValidator::class . ' does not exist') ], - 4 => [\Magento\Framework\App\State::class, $appState], - 5 => [Registry::class, $registry], - 6 => [Manager::class, $cacheManager], - 7 => [Collection::class, $this->indexerMock], - 8 => [IndexerRegistry::class, $this->indexerRegistryMock], - 9 => [IndexerRegistry::class, $this->indexerRegistryMock] + 5 => [\Magento\Framework\App\State::class, $appState], + 7 => [Registry::class, $registry], + 11 => [Manager::class, $cacheManager] ]; $withArgs = $willReturnArgs = []; @@ -1181,15 +1130,6 @@ public function testInstallWithUnresolvableRemoteStorageValidator() ->withConsecutive(...$withArgs) ->willReturnOnConsecutiveCalls(...$willReturnArgs); - $this->indexerMock->expects($this->once())->method('getAllIds')->willReturn( - [ - 'catalog_category_product', - 'catalog_product_category', - ] - ); - $this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn( - $this->indexerInterfaceMock - ); $this->adminFactory->expects(static::any())->method('create')->willReturn( $this->createMock(AdminAccount::class) );