-
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
Get CI/CD Working #33
Changes from all commits
23c7971
79fd4c1
c74ac22
606008e
f811529
53e0025
6c1f6f3
cd8ec0d
1163a2d
3ecce64
5d72c0c
aeec925
d9ecd81
f2d0007
3b9df94
7c864c4
5baef28
f4f53d5
48df560
b6173db
e95b857
89ba261
b27b2e2
9e92243
1660271
570d3bf
0b37214
432611b
0c2c12e
9fc5dd2
44f33b0
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
paths: | ||
- '**/*' | ||
|
||
jobs: | ||
test-android-sdk: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Check out Java SDK | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: 'Eppo-exp/android-sdk' | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'adopt' | ||
|
||
- name: 'Set up GCP SDK' | ||
uses: 'google-github-actions/setup-gcloud@v0' | ||
|
||
- name: Restore gradle.properties | ||
env: | ||
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} | ||
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} | ||
shell: bash | ||
run: | | ||
mkdir -p ~/.gradle/ | ||
echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV | ||
echo "MAVEN_USERNAME=${MAVEN_USERNAME}" > ~/.gradle/gradle.properties | ||
echo "MAVEN_PASSWORD=${MAVEN_PASSWORD}" >> ~/.gradle/gradle.properties | ||
|
||
- name: Set up test data | ||
run: make test-data | ||
|
||
- name: Spin up emulator and run tests | ||
id: testing | ||
uses: ReactiveCircus/android-emulator-runner@v2 | ||
with: | ||
api-level: 33 | ||
target: google_apis | ||
arch: x86_64 | ||
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -dns-server 8.8.8.8 | ||
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.
A bug in Android resulted in newer images not having valid DNS, and thus no internet, so we need to specify this. |
||
script: | | ||
echo "Emulator started" | ||
adb logcat -c # clear logs | ||
mkdir -p app/ # create directory | ||
touch app/emulator.log # create log file | ||
chmod 777 app/emulator.log # allow writing to log file | ||
adb logcat | grep EppoSDK >> app/emulator.log & # pipe all logcat messages into log file as a background process | ||
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 use |
||
./gradlew connectedCheck # run tests | ||
|
||
- name: Upload Emulator Logs | ||
if: always() | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: emulator logs | ||
path: app/emulator.log | ||
|
||
- name: Upload Test Report | ||
if: always() | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: report | ||
path: /Users/runner/work/android-sdk/android-sdk/eppo/build/reports/androidTests/connected/index.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,7 @@ android { | |
|
||
defaultConfig { | ||
namespace "cloud.eppo.android" | ||
|
||
gradle.startParameter.taskNames.each { | ||
if (it.contains("AndroidTest") || it.contains('connectedCheck')) { | ||
minSdk 33 // required to use wiremock in tests | ||
} else { | ||
minSdk 21 | ||
} | ||
} | ||
minSdk 21 | ||
targetSdk 33 | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
|
@@ -63,17 +56,16 @@ ext.versions = [ | |
"androidx_runner": "1.5.2", | ||
"gson": "2.9.1", | ||
"okhttp": "4.10.0", | ||
"wiremock": "2.34.0" | ||
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. 🪓 |
||
"commonsio": "2.14.0" | ||
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 were using some classes, in apache commons, that came with Wiremock outside of our mock server. |
||
] | ||
|
||
|
||
dependencies { | ||
testImplementation "junit:junit:${versions.junit}" | ||
androidTestImplementation "com.github.tomakehurst:wiremock-jre8:${versions.wiremock}" | ||
androidTestImplementation "androidx.test.ext:junit:${versions.androidx_junit}" | ||
androidTestImplementation "androidx.test:core:${versions.androidx_core}" | ||
androidTestImplementation "androidx.test:runner:${versions.androidx_runner}" | ||
|
||
androidTestImplementation "commons-io:commons-io:${versions.commonsio}" | ||
implementation("com.google.code.gson:gson:${versions.gson}") | ||
implementation("com.squareup.okhttp3:okhttp:${versions.okhttp}") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,17 @@ | |
import android.content.res.AssetManager; | ||
import androidx.test.core.app.ApplicationProvider; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import org.apache.commons.io.Charsets; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
|
||
import org.apache.commons.io.Charsets; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
|
@@ -38,11 +36,8 @@ | |
import cloud.eppo.android.dto.adapters.EppoValueAdapter; | ||
|
||
public class EppoClientTest { | ||
private static final String TAG = EppoClientTest.class.getSimpleName(); | ||
private static final int TEST_PORT = 4001; | ||
private static final String HOST = "http://localhost:" + TEST_PORT; | ||
private static final String INVALID_HOST = "http://localhost:" + (TEST_PORT + 1); | ||
private WireMockServer mockServer; | ||
private static final String TEST_HOST = "http://us-central1-eppo-prod-312905.cloudfunctions.net/serveGithubRacTestFile"; | ||
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. Ideally this is some nice DNS thing but not needed |
||
private static final String INVALID_HOST = "http://thisisabaddomainforthistest.com"; | ||
private Gson gson = new GsonBuilder() | ||
.registerTypeAdapter(EppoValue.class, new EppoValueAdapter()) | ||
.registerTypeAdapter(AssignmentValueType.class, new AssignmentValueTypeAdapter(AssignmentValueType.STRING)) | ||
|
@@ -154,34 +149,18 @@ public void onError(String errorMessage) { | |
lock.await(2000, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
@Before | ||
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. Setting one up once before all tests just caused issues. |
||
public void init() { | ||
setupMockRacServer(); | ||
|
||
try { | ||
initClient(HOST, true, true); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
fail(); | ||
} | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
this.mockServer.stop(); | ||
deleteCacheFiles(); | ||
} | ||
|
||
private void setupMockRacServer() { | ||
this.mockServer = new WireMockServer(TEST_PORT); | ||
this.mockServer.start(); | ||
String racResponseJson = getMockRandomizedAssignmentResponse(); | ||
this.mockServer.stubFor(WireMock.get(WireMock.urlMatching(".*randomized_assignment.*")) | ||
.willReturn(WireMock.okJson(racResponseJson))); | ||
} | ||
|
||
@Test | ||
public void testAssignments() { | ||
try { | ||
initClient(TEST_HOST, true, true); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
runTestCases(); | ||
} | ||
|
||
|
@@ -202,12 +181,13 @@ private void runTestCases() { | |
@Test | ||
public void testCachedAssignments() { | ||
try { | ||
initClient(HOST, false, true); // ensure cache is populated | ||
initClient(INVALID_HOST, false, false); // invalid port to force to use cache | ||
initClient(TEST_HOST, false, true); // ensure cache is populated | ||
|
||
// wait for a bit since file is loaded asynchronously | ||
System.out.println("Sleeping for a bit to wait for cache population to complete"); | ||
Thread.sleep(1000); | ||
|
||
initClient(INVALID_HOST, false, false); // invalid port to force to use cache | ||
Comment on lines
-206
to
+190
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. HUGE |
||
} catch (Exception e) { | ||
fail(); | ||
} | ||
|
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.
It's ok these aren't populated in this repo, they just need to be defined (even if empty string)