Skip to content

Commit

Permalink
Bump version to 1.0.5 (#42)
Browse files Browse the repository at this point in the history
* bump version

* initialize latch each time

* clean up InterruptedException
  • Loading branch information
aarsilv committed Apr 8, 2024
1 parent 7cc95f0 commit c04fe9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion eppo/build.gradle
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "cloud.eppo"
version = "1.0.4"
version = "1.0.5"

android {
compileSdk 33
Expand Down
63 changes: 27 additions & 36 deletions eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java
Expand Up @@ -6,10 +6,12 @@
import static org.junit.Assert.assertTrue;

import static cloud.eppo.android.ConfigCacheFile.CACHE_FILE_NAME;
import static cloud.eppo.android.util.Utils.logTag;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.util.Log;

import androidx.test.core.app.ApplicationProvider;

Expand Down Expand Up @@ -49,13 +51,13 @@
import cloud.eppo.android.dto.adapters.EppoValueAdapter;

public class EppoClientTest {
private static final String TAG = logTag(EppoClient.class);
private static final String TEST_HOST = "https://us-central1-eppo-qa.cloudfunctions.net/serveGitHubRacTestFile";
private static final String INVALID_HOST = "https://thisisabaddomainforthistest.com";
private Gson gson = new GsonBuilder()
.registerTypeAdapter(EppoValue.class, new EppoValueAdapter())
.registerTypeAdapter(AssignmentValueType.class, new AssignmentValueTypeAdapter(AssignmentValueType.STRING))
.create();
private CountDownLatch lock = new CountDownLatch(1);

static class SubjectWithAttributes {
String subjectKey;
Expand Down Expand Up @@ -135,12 +137,13 @@ private void deleteCacheFiles() {
sharedPreferences.edit().clear().commit();
}

private void initClient(String host, boolean throwOnCallackError, boolean shouldDeleteCacheFiles, boolean isGracefulMode)
throws InterruptedException {
private void initClient(String host, boolean throwOnCallackError, boolean shouldDeleteCacheFiles, boolean isGracefulMode) {
if (shouldDeleteCacheFiles) {
deleteCacheFiles();
}

CountDownLatch lock = new CountDownLatch(1);

new EppoClient.Builder()
.application(ApplicationProvider.getApplicationContext())
.apiKey("mock-api-key")
Expand All @@ -149,11 +152,13 @@ private void initClient(String host, boolean throwOnCallackError, boolean should
.callback(new InitializationCallback() {
@Override
public void onCompleted() {
Log.w(TAG, "Test client onCompleted callback");
lock.countDown();
}

@Override
public void onError(String errorMessage) {
Log.w(TAG, "Test client onError callback");
if (throwOnCallackError) {
throw new RuntimeException("Unable to initialize: "+errorMessage);
}
Expand All @@ -162,8 +167,12 @@ public void onError(String errorMessage) {
})
.buildAndInit();

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

Expand All @@ -174,21 +183,13 @@ public void teardown() {

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

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

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

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

EppoClient realClient = EppoClient.getInstance();
EppoClient spyClient = spy(realClient);
Expand Down Expand Up @@ -264,18 +261,15 @@ private void runTestCases() {

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

// wait for a bit since cache file is loaded asynchronously
waitForPopulatedCache();
// wait for a bit since cache file is loaded asynchronously
waitForPopulatedCache();

// 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

// 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 @@ -388,7 +382,7 @@ public void testInvalidConfigJSON() {


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

initClient(TEST_HOST, false, false, false);

String result = EppoClient.getInstance().getStringAssignment("dummy subject", "dummy flag");
assertNull(result);
Expand Down

0 comments on commit c04fe9c

Please sign in to comment.