@@ -202,7 +202,7 @@ public function testReplicaRebuild(): void
202
202
*/
203
203
public function testReplicaSync (): void
204
204
{
205
- $ primaryIndexName = $ this ->getIndexName ( ' default ' ) ;
205
+ $ primaryIndexName = $ this ->indexName ;
206
206
207
207
// Make one replica virtual
208
208
$ this ->mockSortUpdate ('created_at ' , 'desc ' , ['virtualReplica ' => 1 ]);
@@ -244,10 +244,77 @@ public function testReplicaDelete(): void
244
244
}
245
245
}
246
246
247
+ /**
248
+ * Test
249
+ * @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
250
+ */
251
+ public function testReplicaDeleteUnreliable (): void
252
+ {
253
+ $ primaryIndexName = $ this ->indexName ;
254
+
255
+ $ sorting = $ this ->populateReplicas (1 );
256
+
257
+ $ currentSettings = $ this ->algoliaHelper ->getSettings ($ primaryIndexName );
258
+ $ this ->assertArrayHasKey ('replicas ' , $ currentSettings );
259
+ $ replicas = $ currentSettings ['replicas ' ];
260
+
261
+ $ this ->assertEquals (count ($ sorting ), count ($ replicas ));
262
+
263
+ $ this ->getCrippledReplicaManager ()->deleteReplicasFromAlgolia (1 );
264
+
265
+ $ newSettings = $ this ->algoliaHelper ->getSettings ($ primaryIndexName );
266
+ $ this ->assertArrayNotHasKey ('replicas ' , $ newSettings );
267
+ foreach ($ replicas as $ replica ) {
268
+ $ this ->assertIndexNotExists ($ this ->extractIndexFromReplicaSetting ($ replica ));
269
+ }
270
+ }
271
+
247
272
protected function extractIndexFromReplicaSetting (string $ setting ): string {
248
273
return preg_replace ('/^virtual\((.*)\)$/ ' , '$1 ' , $ setting );
249
274
}
250
275
276
+ /**
277
+ * If a replica fails to detach from the primary it can create deletion errors
278
+ * Typically this is the result of latency even if task reports as completed from the API (hypothesis)
279
+ * This aims to reproduce this potential scenario by not disassociating the replica
280
+ *
281
+ */
282
+ protected function getCrippledReplicaManager (): ReplicaManagerInterface
283
+ {
284
+ $ mockedClass = \Algolia \AlgoliaSearch \Service \Product \ReplicaManager::class;
285
+ $ mockedMethod = 'clearReplicasSettingInAlgolia ' ;
286
+ $ mockedReplicaManager = $ this ->getMockBuilder ($ mockedClass )
287
+ ->setConstructorArgs ([
288
+ $ this ->objectManager ->get (ConfigHelper::class),
289
+ $ this ->objectManager ->get (AlgoliaHelper::class),
290
+ $ this ->objectManager ->get (ReplicaState::class),
291
+ $ this ->objectManager ->get (VirtualReplicaValidatorFactory::class),
292
+ $ this ->objectManager ->get (IndexNameFetcher::class),
293
+ $ this ->objectManager ->get (StoreNameFetcher::class),
294
+ $ this ->objectManager ->get (SortingTransformer::class),
295
+ $ this ->objectManager ->get (StoreManagerInterface::class),
296
+ $ this ->objectManager ->get (Logger::class)
297
+ ])
298
+ ->onlyMethods ([$ mockedMethod ])
299
+ ->getMock ();
300
+ $ mockedReplicaManager
301
+ ->expects ($ this ->once ())
302
+ ->method ($ mockedMethod )
303
+ ->willReturnCallback (
304
+ function (...$ params )
305
+ use ($ mockedClass , $ mockedMethod , $ mockedReplicaManager )
306
+ {
307
+ // DO NOTHING
308
+ return ;
309
+
310
+ // If aiming to test a throttle on retry invoke after a specified number of failures
311
+ //$originalMethod = new \ReflectionMethod($mockedClass, $mockedMethod);
312
+ //return $originalMethod->invoke($mockedReplicaManager, ...$params);
313
+ }
314
+ );
315
+ return $ mockedReplicaManager ;
316
+ }
317
+
251
318
/**
252
319
* Populate replica indices for test based on store id and return sorting configuration used
253
320
*
0 commit comments