Skip to content

Commit 4b4ffa6

Browse files
authored
fix: tie into lifecycle instead of sleeping for flakey test (#172)
1 parent f25c375 commit 4b4ffa6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ public void testPollingClient() throws ExecutionException, InterruptedException
401401
EppoHttpClient mockHttpClient = mock(EppoHttpClient.class);
402402

403403
CountDownLatch pollLatch = new CountDownLatch(1);
404+
CountDownLatch configActivatedLatch = new CountDownLatch(1);
404405

405406
// The poller fetches synchronously so let's return the boolean flag config
406407
when(mockHttpClient.get(anyString()))
@@ -433,6 +434,10 @@ public void testPollingClient() throws ExecutionException, InterruptedException
433434
.isGracefulMode(false);
434435

435436
EppoClient eppoClient = clientBuilder.buildAndInitAsync().get();
437+
eppoClient.onConfigurationChange(
438+
(config) -> {
439+
configActivatedLatch.countDown();
440+
});
436441

437442
// Empty config on initialization
438443
verify(mockHttpClient, times(1)).getAsync(anyString());
@@ -441,10 +446,10 @@ public void testPollingClient() throws ExecutionException, InterruptedException
441446
// Wait for the client to send the "fetch"
442447
assertTrue("Polling did not occur within timeout", pollLatch.await(5, TimeUnit.SECONDS));
443448

444-
// Sleep a short period to allow the polling mechanism to complete writing the config.
445-
// The above latch releases immediately after the config is "fetched", not necessarily before
446-
// the config is applied.
447-
Thread.sleep(150);
449+
// Wait for the client to apply the fetch and notify of config change.
450+
assertTrue(
451+
"Configuration not activated within timeout",
452+
configActivatedLatch.await(250, TimeUnit.MILLISECONDS));
448453

449454
// Assignment is now true.
450455
assertTrue(eppoClient.getBooleanAssignment("bool_flag", "subject1", false));

0 commit comments

Comments
 (0)