Skip to content

Commit

Permalink
clear shared prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
aarsilv committed Apr 5, 2024
1 parent c879c5f commit c0d5a12
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions eppo/src/androidTest/java/cloud/eppo/android/EppoClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c0d5a12

Please sign in to comment.