@@ -172,15 +172,10 @@ protected function mockSortUpdate(string $sortAttr, string $sortDir, array $attr
172
172
*/
173
173
public function testReplicaRebuild (): void
174
174
{
175
- $ primaryIndexName = $ this ->getIndexName ('default ' );
176
-
175
+ // Make one replica virtual
177
176
$ this ->mockSortUpdate ('price ' , 'desc ' , ['virtualReplica ' => 1 ]);
178
- $ sorting = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Service \Product \SortingTransformer::class)->getSortingIndices (1 , null , null , true );
179
177
180
- $ syncCmd = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Console \Command \ReplicaSyncCommand::class);
181
- $ this ->mockProperty ($ syncCmd , 'output ' , \Symfony \Component \Console \Output \OutputInterface::class);
182
- $ syncCmd ->syncReplicas ();
183
- $ this ->algoliaHelper ->waitLastTask ();
178
+ $ sorting = $ this ->populateReplicas (1 );
184
179
185
180
$ rebuildCmd = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Console \Command \ReplicaRebuildCommand::class);
186
181
$ this ->invokeMethod (
@@ -193,12 +188,9 @@ public function testReplicaRebuild(): void
193
188
);
194
189
$ this ->algoliaHelper ->waitLastTask ();
195
190
196
- $ currentSettings = $ this ->algoliaHelper ->getSettings ($ primaryIndexName );
197
- $ this ->assertArrayHasKey ('replicas ' , $ currentSettings );
198
- $ replicas = $ currentSettings ['replicas ' ];
191
+ $ replicas = $ this ->assertReplicasCreated ($ sorting );
199
192
200
- $ this ->assertEquals (count ($ sorting ), count ($ replicas ));
201
- $ this ->assertSortToReplicaConfigParity ($ primaryIndexName , $ sorting , $ replicas );
193
+ $ this ->assertSortToReplicaConfigParity ($ this ->indexName , $ sorting , $ replicas );
202
194
}
203
195
204
196
/**
@@ -209,17 +201,33 @@ public function testReplicaRebuild(): void
209
201
*/
210
202
public function testReplicaSync (): void
211
203
{
212
- $ primaryIndexName = $ this ->indexName ;
213
-
214
204
// Make one replica virtual
215
205
$ this ->mockSortUpdate ('created_at ' , 'desc ' , ['virtualReplica ' => 1 ]);
216
206
217
207
$ sorting = $ this ->populateReplicas (1 );
218
208
219
209
$ replicas = $ this ->assertReplicasCreated ($ sorting );
220
210
221
- $ this ->assertEquals (count ($ sorting ), count ($ replicas ));
222
- $ this ->assertSortToReplicaConfigParity ($ primaryIndexName , $ sorting , $ replicas );
211
+ $ this ->assertSortToReplicaConfigParity ($ this ->indexName , $ sorting , $ replicas );
212
+ }
213
+
214
+ /**
215
+ * @magentoConfigFixture current_store algoliasearch_credentials/credentials/enable_backend 0
216
+ * @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
217
+ * @throws AlgoliaException
218
+ * @throws ExceededRetriesException
219
+ * @throws \ReflectionException
220
+ */
221
+ public function testReplicaSyncDisabled (): void
222
+ {
223
+ $ primaryIndexName = $ this ->indexName ;
224
+ $ settings = $ this ->algoliaHelper ->getSettings ($ this ->indexName );
225
+ $ this ->assertArrayNotHasKey (ReplicaManager::ALGOLIA_SETTINGS_KEY_REPLICAS , $ settings );
226
+
227
+ $ this ->populateReplicas (1 );
228
+
229
+ $ newSettings = $ this ->algoliaHelper ->getSettings ($ this ->indexName );
230
+ $ this ->assertArrayNotHasKey (ReplicaManager::ALGOLIA_SETTINGS_KEY_REPLICAS , $ newSettings );
223
231
}
224
232
225
233
/**
@@ -252,14 +260,17 @@ public function testReplicaDeleteUnreliable(): void
252
260
253
261
/**
254
262
* Test the RebuildReplicasPatch with API failures
263
+ * @magentoConfigFixture current_store algoliasearch_credentials/credentials/enable_backend 1
255
264
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
256
265
*/
257
266
public function testReplicaRebuildPatch (): void
258
267
{
259
- $ sorting = $ this ->populateReplicas (1 );
260
- $ replicas = $ this ->assertReplicasCreated ($ sorting );
261
-
268
+ $ currentStoreId = 1 ;
262
269
$ this ->assertTrue ($ this ->configHelper ->credentialsAreConfigured (), "Credentials not available to apply patch. " );
270
+ $ this ->assertTrue ($ this ->replicaManager ->isReplicaSyncEnabled ($ currentStoreId ), "Replica sync is not enabled for test store $ currentStoreId. " );
271
+
272
+ $ sorting = $ this ->populateReplicas ($ currentStoreId );
273
+ $ replicas = $ this ->assertReplicasCreated ($ sorting );
263
274
264
275
$ patch = new \Algolia \AlgoliaSearch \Setup \Patch \Data \RebuildReplicasPatch (
265
276
$ this ->objectManager ->get (ModuleDataSetupInterface::class),
@@ -275,7 +286,9 @@ public function testReplicaRebuildPatch(): void
275
286
$ patch ->apply ();
276
287
277
288
$ this ->algoliaHelper ->waitLastTask ();
278
- $ this ->assertEquals (count ($ sorting ), count ($ replicas ));
289
+
290
+ $ replicas = $ this ->assertReplicasCreated ($ sorting );
291
+
279
292
$ this ->assertSortToReplicaConfigParity ($ this ->indexName , $ sorting , $ replicas );
280
293
}
281
294
0 commit comments