Skip to content

Commit

Permalink
get working again
Browse files Browse the repository at this point in the history
  • Loading branch information
aarsilv committed Apr 5, 2024
1 parent 9cdeca0 commit 0800766
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ private void deleteCacheFiles() {
deleteFileIfExists(CACHE_FILE_NAME);
}

private void initClient(String host, boolean throwOnCallackError, boolean shouldDeleteCacheFiles, boolean isGracefulMode) {
private void initClient(String host, boolean throwOnCallackError, boolean shouldDeleteCacheFiles, boolean isGracefulMode)
throws InterruptedException {
if (shouldDeleteCacheFiles) {
deleteCacheFiles();
}
Expand All @@ -157,12 +158,8 @@ public void onError(String errorMessage) {
})
.buildAndInit();

try {
if (!lock.await(10000, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("Request for RAC did not complete within timeout");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
if(!lock.await(10000, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("Request for RAC did not complete within timeout");
}
}

Expand All @@ -173,13 +170,21 @@ public void teardown() {

@Test
public void testAssignments() {
initClient(TEST_HOST, true, true, false);
try {
initClient(TEST_HOST, true, true, false);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
runTestCases();
}

@Test
public void testErrorGracefulModeOn() {
initClient(TEST_HOST, false, true, true);
try {
initClient(TEST_HOST, false, true, true);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

EppoClient realClient = EppoClient.getInstance();
EppoClient spyClient = spy(realClient);
Expand Down Expand Up @@ -208,7 +213,11 @@ public void testErrorGracefulModeOn() {

@Test
public void testErrorGracefulModeOff() {
initClient(TEST_HOST, false, true, false);
try {
initClient(TEST_HOST, false, true, false);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

EppoClient realClient = EppoClient.getInstance();
EppoClient spyClient = spy(realClient);
Expand Down Expand Up @@ -244,22 +253,26 @@ private void runTestCases() {
}
System.out.println("We ran this many tests: " + testsRan);
assertTrue("Did not run any test cases", testsRan > 0);
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Test
public void testCachedAssignments() {
// First initialize successfully
initClient(TEST_HOST, false, true, false); // ensure cache is populated

// wait for a bit since cache file is loaded asynchronously
waitForNonNullAssignment();
try {
// First initialize successfully
initClient(TEST_HOST, false, true, false); // ensure cache is populated

// Then reinitialize with a bad host so we know it's using the cached RAC built from the first initialization
initClient(INVALID_HOST, false, false, false); // invalid port to force to use cache
// wait for a bit since cache file is loaded asynchronously
System.out.println("Sleeping for a bit to wait for cache population to complete");
Thread.sleep(10000);

// Then reinitialize with a bad host so we know it's using the cached RAC built from the first initialization
initClient(INVALID_HOST, false, false, false); // invalid port to force to use cache
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
runTestCases();
}

Expand Down Expand Up @@ -372,7 +385,7 @@ public void testInvalidConfigJSON() {


initClient(TEST_HOST, true, true, false);
} catch (NoSuchFieldException | IllegalAccessException e) {
} catch (InterruptedException | NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
} finally {
if (httpClientOverrideField != null) {
Expand Down Expand Up @@ -400,8 +413,12 @@ public void testCachedBadResponseAllowsLaterFetching() {
} catch (IOException e) {
throw new RuntimeException(e);
}
initClient(TEST_HOST, false, false, false);
;
try {
initClient(TEST_HOST, false, false, false);
} catch (InterruptedException e) {
throw new RuntimeException(e);
};

String result = EppoClient.getInstance().getStringAssignment("dummy subject", "dummy flag");
assertNull(result);
// Failure callback will have fired from cache read error, but configuration request will still be fired off on init
Expand Down

0 comments on commit 0800766

Please sign in to comment.