Skip to content

Commit aa36598

Browse files
committed
MAGE-1138: add integration test
1 parent f690735 commit aa36598

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

Setup/Patch/Schema/ConfigPatch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ConfigPatch implements SchemaPatchInterface
6868
'algoliasearch_queue/queue/active' => '0',
6969
'algoliasearch_queue/queue/number_of_job_to_run' => '5',
7070
'algoliasearch_queue/queue/number_of_retries' => '3',
71+
'algoliasearch_queue/queue/use_tmp_index' => '1',
7172

7273
'algoliasearch_cc_analytics/cc_analytics_group/enable' => '0',
7374
'algoliasearch_cc_analytics/cc_analytics_group/is_selector' => '.ais-Hits-item a.result, .ais-InfiniteHits-item a.result',

Test/Integration/Indexing/Queue/QueueTest.php

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Algolia\AlgoliaSearch\Test\Integration\Indexing\Queue;
44

55
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
6+
use Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper;
67
use Algolia\AlgoliaSearch\Model\Indexer\QueueRunner;
78
use Algolia\AlgoliaSearch\Model\IndicesConfigurator;
89
use Algolia\AlgoliaSearch\Model\Job;
@@ -44,11 +45,11 @@ protected function setUp(): void
4445
public function testFill()
4546
{
4647
$this->resetConfigs([
47-
ConfigHelper::NUMBER_OF_JOB_TO_RUN,
48+
QueueHelper::NUMBER_OF_JOB_TO_RUN,
4849
ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE,
4950
]);
5051

51-
$this->setConfig(ConfigHelper::IS_ACTIVE, '1');
52+
$this->setConfig(QueueHelper::IS_ACTIVE, '1');
5253
$this->connection->query('TRUNCATE TABLE algoliasearch_queue');
5354

5455
$productBatchQueueProcessor = $this->objectManager->get(ProductBatchQueueProcessor::class);
@@ -84,7 +85,7 @@ public function testFill()
8485

8586
public function testExecute()
8687
{
87-
$this->setConfig(ConfigHelper::IS_ACTIVE, '1');
88+
$this->setConfig(QueueHelper::IS_ACTIVE, '1');
8889
$this->connection->query('TRUNCATE TABLE algoliasearch_queue');
8990

9091
$productBatchQueueProcessor = $this->objectManager->get(ProductBatchQueueProcessor::class);
@@ -136,16 +137,57 @@ public function testExecute()
136137
$this->assertEquals(0, count($rows));
137138
}
138139

140+
public function testTmpIndexConfig()
141+
{
142+
$this->setConfig(QueueHelper::IS_ACTIVE, '1');
143+
// Setting "Use a temporary index for full products reindex" configuration to "No"
144+
$this->setConfig(QueueHelper::USE_TMP_INDEX, '0');
145+
$this->connection->query('TRUNCATE TABLE algoliasearch_queue');
146+
147+
$productBatchQueueProcessor = $this->objectManager->get(ProductBatchQueueProcessor::class);
148+
$productBatchQueueProcessor->processBatch(1);
149+
150+
$rows = $this->connection->query('SELECT * FROM algoliasearch_queue')->fetchAll();
151+
// Without temporary index enabled, there are only 2 jobs (saveConfigurationToAlgolia and buildIndexFull)
152+
$this->assertEquals(2, count($rows));
153+
154+
$indexingJob = $rows[1];
155+
$jobData = json_decode($indexingJob['data'], true);
156+
157+
$this->assertEquals('buildIndexFull', $indexingJob['method']);
158+
$this->assertFalse($jobData['options']['useTmpIndex']);
159+
160+
/** @var Queue $queue */
161+
$queue = $this->objectManager->get(Queue::class);
162+
163+
// Run the first job (saveSettings)
164+
$queue->runCron(1, true);
165+
166+
$this->algoliaConnector->waitLastTask();
167+
168+
$indices = $this->algoliaConnector->listIndexes();
169+
170+
$existsDefaultTmpIndex = false;
171+
foreach ($indices['items'] as $index) {
172+
if ($index['name'] === $this->indexPrefix . 'default_products_tmp') {
173+
$existsDefaultTmpIndex = true;
174+
}
175+
}
176+
// Checking if the temporary index hasn't been created
177+
$this->assertFalse($existsDefaultTmpIndex, 'Temporary index exists and it should not');
178+
}
179+
139180
public function testSettings()
140181
{
141182
$this->resetConfigs([
142-
ConfigHelper::NUMBER_OF_JOB_TO_RUN,
183+
QueueHelper::NUMBER_OF_JOB_TO_RUN,
143184
ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE,
144185
ConfigHelper::FACETS,
186+
QueueHelper::USE_TMP_INDEX,
145187
ConfigHelper::PRODUCT_ATTRIBUTES
146188
]);
147189

148-
$this->setConfig(ConfigHelper::IS_ACTIVE, '1');
190+
$this->setConfig(QueueHelper::IS_ACTIVE, '1');
149191

150192
$this->connection->query('DELETE FROM algoliasearch_queue');
151193

@@ -178,8 +220,8 @@ public function testSettings()
178220

179221
public function testMergeSettings()
180222
{
181-
$this->setConfig(ConfigHelper::IS_ACTIVE, '1');
182-
$this->setConfig(ConfigHelper::NUMBER_OF_JOB_TO_RUN, 1);
223+
$this->setConfig(QueueHelper::IS_ACTIVE, '1');
224+
$this->setConfig(QueueHelper::NUMBER_OF_JOB_TO_RUN, 1);
183225
$this->setConfig(ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE, 300);
184226

185227
$this->connection->query('DELETE FROM algoliasearch_queue');
@@ -791,7 +833,7 @@ public function testGetJobs()
791833
public function testHugeJob()
792834
{
793835
// Default value - maxBatchSize = 1000
794-
$this->setConfig(ConfigHelper::NUMBER_OF_JOB_TO_RUN, 10);
836+
$this->setConfig(QueueHelper::NUMBER_OF_JOB_TO_RUN, 10);
795837
$this->setConfig(ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE, 100);
796838

797839
$productIds = range(1, 5000);
@@ -829,7 +871,7 @@ public function testHugeJob()
829871
public function testMaxSingleJobSize()
830872
{
831873
// Default value - maxBatchSize = 1000
832-
$this->setConfig(ConfigHelper::NUMBER_OF_JOB_TO_RUN, 10);
874+
$this->setConfig(QueueHelper::NUMBER_OF_JOB_TO_RUN, 10);
833875
$this->setConfig(ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE, 100);
834876

835877
$productIds = range(1, 99);
@@ -870,13 +912,13 @@ public function testMaxSingleJobSize()
870912
public function testMaxSingleJobsSizeOnProductReindex()
871913
{
872914
$this->resetConfigs([
873-
ConfigHelper::NUMBER_OF_JOB_TO_RUN,
915+
QueueHelper::NUMBER_OF_JOB_TO_RUN,
874916
ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE,
875917
]);
876918

877-
$this->setConfig(ConfigHelper::IS_ACTIVE, '1');
919+
$this->setConfig(QueueHelper::IS_ACTIVE, '1');
878920

879-
$this->setConfig(ConfigHelper::NUMBER_OF_JOB_TO_RUN, 10);
921+
$this->setConfig(QueueHelper::NUMBER_OF_JOB_TO_RUN, 10);
880922
$this->setConfig(ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE, 100);
881923

882924
$this->connection->query('TRUNCATE TABLE algoliasearch_queue');

0 commit comments

Comments
 (0)