-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include additional error information in emulator log #34
Changes from all commits
6857a2b
b70301f
1699ef6
cf34ff2
257717a
b522923
d15819b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,8 @@ | |
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.res.AssetManager; | ||
import android.util.Log; | ||
|
||
import androidx.test.core.app.ApplicationProvider; | ||
|
||
|
@@ -45,9 +43,8 @@ | |
import cloud.eppo.android.dto.adapters.EppoValueAdapter; | ||
|
||
public class EppoClientTest { | ||
private static final String TAG = logTag(EppoClientTest.class); | ||
private static final String TEST_HOST = "http://us-central1-eppo-prod-312905.cloudfunctions.net/serveGithubRacTestFile"; | ||
private static final String INVALID_HOST = "http://thisisabaddomainforthistest.com"; | ||
private static final String TEST_HOST = "https://us-central1-eppo-prod-312905.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)) | ||
|
@@ -150,14 +147,16 @@ public void onCompleted() { | |
@Override | ||
public void onError(String errorMessage) { | ||
if (throwOnCallackError) { | ||
throw new RuntimeException("Unable to initialize"); | ||
throw new RuntimeException("Unable to initialize: "+errorMessage); | ||
} | ||
lock.countDown(); | ||
} | ||
}) | ||
.buildAndInit(); | ||
|
||
lock.await(2000, TimeUnit.MILLISECONDS); | ||
if(!lock.await(10000, TimeUnit.MILLISECONDS)) { | ||
throw new RuntimeException("Request for RAC did not complete within timeout"); | ||
} | ||
Comment on lines
+157
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the core change. If First testing this on my bad home wifi, I hit the error 😅 . So, I've extended the timeout to a generous 10 seconds. However, since it's using this await, most of the time we won't actually wait that long. |
||
} | ||
|
||
@After | ||
|
@@ -179,8 +178,6 @@ public void testAssignments() { | |
public void testErrorGracefulModeOn() { | ||
try { | ||
initClient(TEST_HOST, false, true, true); | ||
System.out.println("Sleeping for a bit to wait for cache population to complete"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need these sleeps since we are no formally waiting for the request to complete. |
||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
@@ -214,8 +211,6 @@ public void testErrorGracefulModeOn() { | |
public void testErrorGracefulModeOff() { | ||
try { | ||
initClient(TEST_HOST, false, true, false); | ||
Log.d(TAG, "Sleeping for a bit to wait for cache population to complete"); | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
@@ -262,12 +257,14 @@ private void runTestCases() { | |
@Test | ||
public void testCachedAssignments() { | ||
try { | ||
// First initialize successfully | ||
initClient(TEST_HOST, false, true, false); // ensure cache is populated | ||
|
||
// wait for a bit since file is loaded asynchronously | ||
// 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(1000); | ||
Thread.sleep(2000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do still need this sleep though, for asynchronous cache repopulation, but I'm doubling it given how unimpressed I am with GitHub action performance. |
||
|
||
// 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); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,21 @@ | |
|
||
import android.util.Log; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.net.HttpURLConnection; | ||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import okhttp3.Call; | ||
import okhttp3.Callback; | ||
import okhttp3.Dns; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
|
@@ -19,17 +27,23 @@ | |
public class EppoHttpClient { | ||
private static final String TAG = logTag(EppoHttpClient.class); | ||
|
||
private final OkHttpClient client = new OkHttpClient().newBuilder() | ||
.connectTimeout(10, TimeUnit.SECONDS) | ||
.readTimeout(10, TimeUnit.SECONDS) | ||
.build(); | ||
private final OkHttpClient client; | ||
|
||
private final String baseUrl; | ||
private final String apiKey; | ||
|
||
public EppoHttpClient(String baseUrl, String apiKey) { | ||
this.baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.client = buildOkHttpClient(); | ||
} | ||
|
||
private static OkHttpClient buildOkHttpClient() { | ||
OkHttpClient.Builder builder = new OkHttpClient().newBuilder() | ||
.connectTimeout(10, TimeUnit.SECONDS) | ||
.readTimeout(10, TimeUnit.SECONDS); | ||
|
||
return builder.build(); | ||
Comment on lines
+38
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made this more obvious it was happening in constructor and set it up for dropping in IpV4-only DNS, which may be needed (but hopefully not 🤞) |
||
} | ||
|
||
public void get(String path, RequestCallback callback) { | ||
|
@@ -45,7 +59,7 @@ public void get(String path, RequestCallback callback) { | |
@Override | ||
public void onResponse(Call call, Response response) { | ||
if (response.isSuccessful()) { | ||
Log.d(TAG, "Fetch successfull"); | ||
Log.d(TAG, "Fetch successful"); | ||
callback.onSuccess(response.body().charStream()); | ||
} else { | ||
switch (response.code()) { | ||
|
@@ -64,10 +78,7 @@ public void onResponse(Call call, Response response) { | |
|
||
@Override | ||
public void onFailure(Call call, IOException e) { | ||
if (BuildConfig.DEBUG) { | ||
e.printStackTrace(); | ||
} | ||
Log.e(TAG, "Http request failure", e); | ||
Log.e(TAG, "Http request failure: "+e.getMessage()+" "+Arrays.toString(e.getStackTrace()), e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More helpful failure log. |
||
callback.onFailure("Unable to fetch from URL "+httpUrl); | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made these
HTTPS