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
- }
273
+ $ updatedApiKey = TestHelper::retry (function () use ($ res ) {
274
+ return TestHelper::getClient ()->getApiKey ($ res ['key ' ]);
275
+ });
281
276
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
- }
292
-
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,9 +286,14 @@ public function testApiKeys()
303
286
$ this ->assertInstanceOf ('Algolia\AlgoliaSearch\Exceptions\NotFoundException ' , $ e );
304
287
}
305
288
306
- TestHelper::getClient ()->restoreApiKey ($ res ['key ' ])->wait ();
289
+ TestHelper::retry (function () use ($ res ) {
290
+ TestHelper::getClient ()->restoreApiKey ($ res ['key ' ])->wait ();
291
+ });
292
+
293
+ $ restoredApiKey = TestHelper::retry (function () use ($ res ) {
294
+ return TestHelper::getClient ()->getApiKey ($ res ['key ' ]);
295
+ });
307
296
308
- $ restoredApiKey = TestHelper::getClient ()->getApiKey ($ res ['key ' ]);
309
297
$ this ->assertEquals ($ acl , $ restoredApiKey ['acl ' ]);
310
298
$ this ->assertEquals ($ params ['description ' ], $ restoredApiKey ['description ' ]);
311
299
0 commit comments