Skip to content

Commit

Permalink
MAGE-870 Integration tests (#1528)
Browse files Browse the repository at this point in the history
* try to re-add integration tests to circleci

* update tests config

* update tests config

* update tests config

* test with another image

* test with another image

* test with another image

* revert changes on circleci

* improve QueueTests

* MAGE-870: remove comments
  • Loading branch information
damcou authored Jun 12, 2024
1 parent 27a936e commit c7f9510
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 82 deletions.
4 changes: 2 additions & 2 deletions Setup/Patch/Schema/ConfigPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ConfigPatch implements SchemaPatchInterface

'algoliasearch_synonyms/synonyms_group/enable_synonyms' => '0',

'algoliasearch_advanced/advanced/number_of_element_by_page' => '300',
'algoliasearch_advanced/queue/number_of_element_by_page' => '300',
'algoliasearch_advanced/advanced/remove_words_if_no_result' => 'allOptional',
'algoliasearch_advanced/advanced/partial_update' => '0',
'algoliasearch_advanced/advanced/customer_groups_enable' => '0',
Expand All @@ -92,7 +92,7 @@ class ConfigPatch implements SchemaPatchInterface
'algoliasearch_advanced/advanced/prevent_backend_rendering' => '0',
'algoliasearch_advanced/advanced/prevent_backend_rendering_display_mode' => 'all',
'algoliasearch_advanced/advanced/backend_rendering_allowed_user_agents' => "Googlebot\nBingbot",
'algoliasearch_advanced/advanced/archive_clear_limit' => '30',
'algoliasearch_advanced/queue/archive_clear_limit' => '30',
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;

class Magento_2_3
class Magento23
{
public $productsOnStockCount = 186;
public $productsOutOfStockCount = 187;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;

class Magento244
class Magento24
{
public $productsOnStockCount = 180;
public $productsOutOfStockCount = 183;
public $productsOutOfStockCount = 181;
public $lastJobDataSize = 13;
public $expectedCategory = 17;
public $expectedCategory = 16;
public $attributesForFaceting = 5;
public $automaticalSetOfCategoryAttributesForFaceting = 4;
public $expectedPages = 9;
public $expectedExcludePages = 7;
public $expectedPages = 6;
public $expectedExcludePages = 4;
}
15 changes: 0 additions & 15 deletions Test/Integration/AssertValues/Magento_2_01.php

This file was deleted.

15 changes: 0 additions & 15 deletions Test/Integration/AssertValues/Magento_2_2.php

This file was deleted.

2 changes: 1 addition & 1 deletion Test/Integration/PagesIndexingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class PagesIndexingTest extends IndexingTestCase
{
public function testOnlyOnStockProducts()
public function testNoExcludedPages()
{
$this->setConfig(
'algoliasearch_autocomplete/autocomplete/excluded_pages',
Expand Down
84 changes: 57 additions & 27 deletions Test/Integration/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,35 @@

class QueueTest extends TestCase
{
private const INCOMPLETE_REASON = "Must revisit transaction handling across connections.";

/** @var JobsCollectionFactory */
private $jobsCollectionFactory;

/** @var AdapterInterface */
private $connection;

/** @var Queue */
private $queue;

public function setUp(): void
{
parent::setUp();

$this->jobsCollectionFactory = $this->getObjectManager()->create(JobsCollectionFactory::class);

/** @var ResourceConnection $resouce */
$resouce = $this->getObjectManager()->create(ResourceConnection::class);
$this->connection = $resouce->getConnection();
/** @var ResourceConnection $resource */
$resource = $this->getObjectManager()->create(ResourceConnection::class);
$this->connection = $resource->getConnection();

$this->queue = $this->getObjectManager()->create(Queue::class);
}

public function testFill()
{
$this->resetConfigs([
'algoliasearch_queue/queue/number_of_job_to_run',
'algoliasearch_advanced/advanced/number_of_element_by_page',
'algoliasearch_advanced/queue/number_of_element_by_page',
]);

$this->setConfig('algoliasearch_queue/queue/active', '1');
Expand Down Expand Up @@ -72,9 +79,14 @@ public function testFill()
}
}

/** @depends testFill */
/**
* @depends testFill
* @magentoDbIsolation disabled
*/
public function testExecute()
{
$this->markTestIncomplete(self::INCOMPLETE_REASON);

$this->setConfig('algoliasearch_queue/queue/active', '1');

/** @var Queue $queue */
Expand Down Expand Up @@ -123,11 +135,14 @@ public function testExecute()
$this->assertEquals(0, count($rows)); */
}

/**
* @magentoDbIsolation disabled
*/
public function testSettings()
{
$this->resetConfigs([
'algoliasearch_queue/queue/number_of_job_to_run',
'algoliasearch_advanced/advanced/number_of_element_by_page',
'algoliasearch_advanced/queue/number_of_element_by_page',
'algoliasearch_instant/instant/facets',
'algoliasearch_products/products/product_additional_attributes',
]);
Expand Down Expand Up @@ -163,11 +178,14 @@ public function testSettings()
$this->assertFalse(empty($settings['searchableAttributes']), 'SearchableAttributes should be set, but they are not.');
}

/**
* @magentoDbIsolation disabled
*/
public function testMergeSettings()
{
$this->setConfig('algoliasearch_queue/queue/active', '1');
$this->setConfig('algoliasearch_queue/queue/number_of_job_to_run', 1);
$this->setConfig('algoliasearch_advanced/advanced/number_of_element_by_page', 300);
$this->setConfig('algoliasearch_advanced/queue/number_of_element_by_page', 300);

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

Expand Down Expand Up @@ -202,6 +220,9 @@ public function testMergeSettings()
$this->assertEquals(['sku'], $settings['disableTypoToleranceOnAttributes']);
}

/**
* @magentoDbIsolation disabled
*/
public function testMerging()
{
$this->connection->query('DELETE FROM algoliasearch_queue');
Expand Down Expand Up @@ -376,6 +397,7 @@ public function testMerging()
],
],
'locked_at' => null,
'debug' => null,
];

/** @var Job $categoryJob */
Expand Down Expand Up @@ -404,13 +426,17 @@ public function testMerging()
],
],
'locked_at' => null,
'debug' => null,
];

/** @var Job $productJob */
$productJob = $mergedJobs[3];
$this->assertEquals($expectedProductJob, $productJob->toArray());
}

/**
* @magentoDbIsolation disabled
*/
public function testMergingWithStaticMethods()
{
$this->connection->query('TRUNCATE TABLE algoliasearch_queue');
Expand Down Expand Up @@ -539,15 +565,12 @@ public function testMergingWithStaticMethods()
],
];

/** @var Queue $queue */
$queue = $this->getObjectManager()->create(Queue::class);

$this->connection->insertMultiple('algoliasearch_queue', $data);

/** @var Job[] $jobs */
$jobs = $this->jobsCollectionFactory->create()->getItems();

$jobs = array_values($this->invokeMethod($queue, 'mergeJobs', [$jobs]));
$jobs = array_values($this->invokeMethod($this->queue, 'mergeJobs', [$jobs]));
$this->assertEquals(12, count($jobs));

$this->assertEquals('rebuildStoreCategoryIndex', $jobs[0]->getMethod());
Expand All @@ -564,8 +587,13 @@ public function testMergingWithStaticMethods()
$this->assertEquals('rebuildStoreProductIndex', $jobs[11]->getMethod());
}

/**
* @magentoDbIsolation disabled
*/
public function testGetJobs()
{
$this->markTestIncomplete(self::INCOMPLETE_REASON);

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

$data = [
Expand Down Expand Up @@ -706,11 +734,8 @@ public function testGetJobs()

$this->connection->insertMultiple('algoliasearch_queue', $data);

/** @var Queue $queue */
$queue = $this->getObjectManager()->create(Queue::class);

$pid = getmypid();
$jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10]);
$jobs = $this->invokeMethod($this->queue, 'getJobs', ['maxJobs' => 10]);
$this->assertEquals(6, count($jobs));

$expectedFirstJob = [
Expand All @@ -736,6 +761,7 @@ public function testGetJobs()
],
],
'locked_at' => null,
'debug' => null,
];

$expectedLastJob = [
Expand All @@ -760,6 +786,7 @@ public function testGetJobs()
],
],
'locked_at' => null,
'debug' => null,
];

/** @var Job $firstJob */
Expand All @@ -780,11 +807,14 @@ public function testGetJobs()
}
}

/**
* @magentoDbIsolation disabled
*/
public function testHugeJob()
{
// Default value - maxBatchSize = 1000
$this->setConfig('algoliasearch_queue/queue/number_of_job_to_run', 10);
$this->setConfig('algoliasearch_advanced/advanced/number_of_element_by_page', 100);
$this->setConfig('algoliasearch_advanced/queue/number_of_element_by_page', 100);

$productIds = range(1, 5000);
$jsonProductIds = json_encode($productIds);
Expand All @@ -794,12 +824,9 @@ public function testHugeJob()
(1, NULL, \'class\', \'rebuildStoreProductIndex\', \'{"store_id":"1","product_ids":' . $jsonProductIds . '}\', 3, 0, \'\', 5000),
(2, NULL, \'class\', \'rebuildStoreProductIndex\', \'{"store_id":"2","product_ids":["9","22"]}\', 3, 0, \'\', 2);');

/** @var Queue $queue */
$queue = $this->getObjectManager()->create(Queue::class);

$pid = getmypid();
/** @var Job[] $jobs */
$jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10]);
$jobs = $this->invokeMethod($this->queue, 'getJobs', ['maxJobs' => 10]);

$this->assertEquals(1, count($jobs));

Expand All @@ -818,11 +845,14 @@ public function testHugeJob()
$this->assertNull($lastJob['pid']);
}

/**
* @magentoDbIsolation disabled
*/
public function testMaxSingleJobSize()
{
// Default value - maxBatchSize = 1000
$this->setConfig('algoliasearch_queue/queue/number_of_job_to_run', 10);
$this->setConfig('algoliasearch_advanced/advanced/number_of_element_by_page', 100);
$this->setConfig('algoliasearch_advanced/queue/number_of_element_by_page', 100);

$productIds = range(1, 99);
$jsonProductIds = json_encode($productIds);
Expand All @@ -832,13 +862,10 @@ public function testMaxSingleJobSize()
(1, NULL, \'class\', \'rebuildStoreProductIndex\', \'{"store_id":"1","product_ids":' . $jsonProductIds . '}\', 3, 0, \'\', 99),
(2, NULL, \'class\', \'rebuildStoreProductIndex\', \'{"store_id":"2","product_ids":["9","22"]}\', 3, 0, \'\', 2);');

/** @var Queue $queue */
$queue = $this->getObjectManager()->create(Queue::class);

$pid = getmypid();

/** @var Job[] $jobs */
$jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10]);
$jobs = $this->invokeMethod($this->queue, 'getJobs', ['maxJobs' => 10]);

$this->assertEquals(2, count($jobs));

Expand All @@ -862,17 +889,20 @@ public function testMaxSingleJobSize()
$this->assertEquals($pid, $lastJob['pid']);
}

/**
* @magentoDbIsolation disabled
*/
public function testMaxSingleJobsSizeOnProductReindex()
{
$this->resetConfigs([
'algoliasearch_queue/queue/number_of_job_to_run',
'algoliasearch_advanced/advanced/number_of_element_by_page',
'algoliasearch_advanced/queue/number_of_element_by_page',
]);

$this->setConfig('algoliasearch_queue/queue/active', '1');

$this->setConfig('algoliasearch_queue/queue/number_of_job_to_run', 10);
$this->setConfig('algoliasearch_advanced/advanced/number_of_element_by_page', 100);
$this->setConfig('algoliasearch_advanced/queue/number_of_element_by_page', 100);

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

Expand Down
Loading

0 comments on commit c7f9510

Please sign in to comment.