diff --git a/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java b/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java index 680ab161..0c8c6cb8 100644 --- a/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java +++ b/eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java @@ -7,6 +7,8 @@ import static cloud.eppo.android.ConfigCacheFile.CACHE_FILE_NAME; +import android.content.Context; +import android.content.SharedPreferences; import android.content.res.AssetManager; import androidx.test.core.app.ApplicationProvider; @@ -129,6 +131,8 @@ private void deleteFileIfExists(String fileName) { private void deleteCacheFiles() { deleteFileIfExists(CACHE_FILE_NAME); + SharedPreferences sharedPreferences = ApplicationProvider.getApplicationContext().getSharedPreferences("eppo", Context.MODE_PRIVATE); + sharedPreferences.edit().clear().commit(); } private void initClient(String host, boolean throwOnCallackError, boolean shouldDeleteCacheFiles, boolean isGracefulMode) @@ -448,6 +452,27 @@ private void waitForPopulatedCache() { } } + // TODO: useful? + private void waitForSharedPreferences() { + long waitStart = System.currentTimeMillis(); + long waitEnd = waitStart + 5 * 1000; // allow up to 5 seconds + boolean sharedPrefsReady = false; + try { + while (!sharedPrefsReady) { + if (System.currentTimeMillis() > waitEnd) { + throw new InterruptedException("Shared preferences never ready"); + } + SharedPreferences sharedPreferences = ApplicationProvider.getApplicationContext().getSharedPreferences("eppo", Context.MODE_PRIVATE); + sharedPrefsReady = !sharedPreferences.getAll().isEmpty(); + if (!sharedPrefsReady) { + Thread.sleep(100); + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + private void waitForNonNullAssignment() { long waitStart = System.currentTimeMillis(); long waitEnd = waitStart + 15 * 1000; // allow up to 15 seconds