2
2
3
3
namespace Algolia \AlgoliaSearch \Tests \Integration ;
4
4
5
- use Algolia \AlgoliaSearch \Exceptions \NotFoundException ;
6
5
use Algolia \AlgoliaSearch \Response \MultiResponse ;
7
6
use Algolia \AlgoliaSearch \SearchClient ;
8
7
use Algolia \AlgoliaSearch \SearchIndex ;
@@ -271,29 +270,13 @@ public function testApiKeys()
271
270
272
271
TestHelper::getClient ()->updateApiKey ($ res ['key ' ], $ newParams )->wait ();
273
272
274
- $ retry = 1 ;
275
- $ time = 100000 ;
276
- $ maxRetries = 100 ;
277
- do {
278
- if ($ retry >= $ maxRetries ) {
279
- break ;
280
- }
281
-
282
- try {
283
- $ updatedApiKey = TestHelper::getClient ()->getApiKey ($ res ['key ' ]);
284
-
285
- if ($ updatedApiKey ['maxHitsPerQuery ' ] !== $ apiKey ['maxHitsPerQuery ' ]) {
286
- $ this ->assertEquals (42 , $ updatedApiKey ['maxHitsPerQuery ' ]);
287
- break ;
288
- }
289
- } catch (NotFoundException $ e ) {
290
- // Try again
291
- }
273
+ $ updatedApiKey = TestHelper::retry (function () use ($ res ) {
274
+ return TestHelper::getClient ()->getApiKey ($ res ['key ' ]);
275
+ }, 1000 , 30 );
292
276
293
- $ retry ++;
294
- $ factor = ceil ($ retry / 10 );
295
- usleep ($ factor * $ time ); // 0.1 second
296
- } while (true );
277
+ if ($ updatedApiKey ['maxHitsPerQuery ' ] !== $ apiKey ['maxHitsPerQuery ' ]) {
278
+ $ this ->assertEquals (42 , $ updatedApiKey ['maxHitsPerQuery ' ]);
279
+ }
297
280
298
281
TestHelper::getClient ()->deleteApiKey ($ res ['key ' ])->wait ();
299
282
@@ -303,34 +286,16 @@ public function testApiKeys()
303
286
$ this ->assertInstanceOf ('Algolia\AlgoliaSearch\Exceptions\NotFoundException ' , $ e );
304
287
}
305
288
306
- $ retry = 1 ;
307
- $ time = 100000 ;
308
- $ maxRetries = 100 ;
309
- do {
310
- try {
311
- TestHelper::getClient ()->restoreApiKey ($ res ['key ' ])->wait ();
312
- } catch (NotFoundException $ e ) {
313
- $ retry ++;
314
- $ factor = ceil ($ retry / 10 );
315
- usleep ($ factor * $ time ); // 0.1 second
316
- continue ;
317
- }
289
+ TestHelper::retry (function () use ($ res ) {
290
+ TestHelper::getClient ()->restoreApiKey ($ res ['key ' ])->wait ();
291
+ }, 1000 , 30 );
318
292
319
- } while ($ retry >= $ maxRetries );
320
-
321
- do {
322
- try {
323
- $ restoredApiKey = TestHelper::getClient ()->getApiKey ($ res ['key ' ]);
324
- $ this ->assertEquals ($ acl , $ restoredApiKey ['acl ' ]);
325
- $ this ->assertEquals ($ params ['description ' ], $ restoredApiKey ['description ' ]);
326
- } catch (NotFoundException $ e ) {
327
- $ retry ++;
328
- $ factor = ceil ($ retry / 10 );
329
- usleep ($ factor * $ time ); // 0.1 second
330
- continue ;
331
- }
293
+ $ restoredApiKey = TestHelper::retry (function () use ($ res ) {
294
+ return TestHelper::getClient ()->getApiKey ($ res ['key ' ]);
295
+ }, 1000 , 30 );
332
296
333
- } while ($ retry >= $ maxRetries );
297
+ $ this ->assertEquals ($ acl , $ restoredApiKey ['acl ' ]);
298
+ $ this ->assertEquals ($ params ['description ' ], $ restoredApiKey ['description ' ]);
334
299
335
300
TestHelper::getClient ()->deleteApiKey ($ res ['key ' ])->wait ();
336
301
}
0 commit comments