Skip to content
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

Test on Android using "release" configuration #6769

Merged
merged 11 commits into from
Jul 5, 2024
42 changes: 37 additions & 5 deletions .github/workflows/pr-realm-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,32 @@ jobs:
~/.android/adb*
key: avd-29

- name: Bundle test app
working-directory: integration-tests/environments/react-native-test-app
run: |
mkdir dist
npx react-native bundle --entry-file index.js --platform android --dev false --minify false --bundle-output dist/main.android.jsbundle --assets-dest dist/res
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use --minify false to avoid test failures from error messages mismatching due to class names being renamed in the bundle.


- name: Generate a keystore for signing
working-directory: integration-tests/environments/react-native-test-app
env:
STORE_PATH: debug.keystore
STORE_PASS: android
KEY_ALIAS: debug-key
KEY_PASS: android
run: |
keytool -genkey -v -keyalg RSA -keysize 2048 -validity 10000 -dname cn=Realm -keystore ${{ env.STORE_PATH }} -storepass ${{ env.STORE_PASS }} -alias ${{ env.KEY_ALIAS }} -keypass ${{ env.KEY_PASS }}
jq --arg storeFile ${{ env.STORE_PATH }} --arg storePassword ${{ env.STORE_PASS }} --arg keyAlias ${{ env.KEY_ALIAS }} --arg keyPassword ${{ env.KEY_PASS }} '. +{android: {signingConfigs: { release: { $storeFile, $storePassword, $keyAlias, $keyPassword } }}}' app.json > patched-app.json
mv patched-app.json app.json
Comment on lines +715 to +717
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generates a temporary keystore and key to sign the release APK and patch the RNTA app.json to pick it up when building the app.


- name: Run tests
env:
PLATFORM: android
# Limit architecture to speed up the build
ORG_GRADLE_PROJECT_reactNativeArchitectures: x86
# Enabling new architecture and bridgeless
ORG_GRADLE_PROJECT_newArchEnabled: true
ORG_GRADLE_PROJECT_bridgelessEnabled: true
Comment on lines +723 to +725
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our native module supports this only on Android at the moment, while #6737 will bring this to iOS too (and refactor the Android implementation too).

MOCHA_REMOTE_CONTEXT: ${{ steps.mocha-env.outputs.context }}
# TODO: Consider passing ORG_GRADLE_PROJECT_reactNativeArchitectures=x86 to limit increase build speed
timeout-minutes: 75
uses: reactivecircus/android-emulator-runner@v2
with:
Expand All @@ -713,6 +734,17 @@ jobs:
arch: x86
ndk: ${{ env.NDK_VERSION }}
cmake: 3.22.1
working-directory: integration-tests/environments/react-native-test-app
script: npx mocha-remote -- concurrently --kill-others-on-fail npm:metro npm:runner

working-directory: integration-tests/environments/react-native-test-app/android
script: |
# Setup port forwarding to Mocha Remote
adb reverse tcp:8090 tcp:8090
# Uninstall the app if already in the snapshot (unlikely but could result in a signature mismatch failure)
adb uninstall com.microsoft.reacttestapp || true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uninstalling here should fix the issues we're having with the Android test app being unable to install on other branches: https://github.com/realm/realm-js/actions/runs/9680928508/job/26757061658?pr=6743#step:16:526

Unable to install /Users/runner/work/realm-js/realm-js/integration-tests/environments/react-native-test-app/android/app/build/outputs/apk/debug/app-debug.apk
[runner] com.android.ddmlib.InstallException: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.microsoft.reacttestapp signatures do not match previously installed version; ignoring!

# Build and install the app
./gradlew installRelease
# Launch the app
# -W wait for launch to complete, to allow the logcat script to find a pid
# -S force stop the target app before starting the activity
adb shell am start -W -S -n com.microsoft.reacttestapp/.MainActivity
# Start Mocha Remote, wrapping logcat
npx mocha-remote -- npm run logcat
4 changes: 2 additions & 2 deletions integration-tests/environments/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
"electron-builder": "^24.9.1",
"mocha-github-actions-reporter": "^0.3.0",
"mocha-junit-reporter": "^2.2.0",
"mocha-remote-cli": "^1.12.2"
"mocha-remote-cli": "^1.12.3"
},
"dependencies": {
"@electron/remote": "^2.1.2",
"@realm/integration-tests": "*",
"fs-extra": "^11.2.0",
"mocha-remote-client": "^1.12.2",
"mocha-remote-client": "^1.12.3",
"@realm/app-importer": "*"
},
"build": {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/environments/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"dependencies": {
"@realm/integration-tests": "*",
"mocha-github-actions-reporter": "^0.3.1",
"mocha-remote-cli": "^1.12.2",
"mocha-remote-client": "^1.12.2",
"mocha-remote-cli": "^1.12.3",
"mocha-remote-client": "^1.12.3",
"realm": "*"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"realm:build-android:debug": "wireit",
"realm:build-android:release": "wireit",
"metro": "react-native start --reset-cache",
"runner": "node harness/runner.js"
"runner": "node harness/runner.js",
"logcat": "adb logcat -v color --pid=$(adb shell pidof -s com.microsoft.reacttestapp)"
},
"wireit": {
"test:android": {
Expand Down Expand Up @@ -130,7 +131,7 @@
},
"dependencies": {
"base-64": "^1.0.0",
"mocha-remote-react-native": "^1.12.2",
"mocha-remote-react-native": "^1.12.3",
Copy link
Member Author

@kraenhansen kraenhansen Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new version avoids transforming errors when the bundle isn't shipped from Metro.

"path-browserify": "^1.0.1",
"react": "18.2.0",
"react-native": "0.74.1",
Expand All @@ -152,8 +153,8 @@
"@rnx-kit/metro-config": "^1.3.15",
"@types/react": "^18.2.6",
"concurrently": "^8.2.2",
"mocha-remote-cli": "^1.12.2",
"mocha-remote-cli": "^1.12.3",
"pod-install": "^0.2.2",
"react-native-test-app": "^3.7.3"
"react-native-test-app": "^3.8.7"
}
}
20 changes: 10 additions & 10 deletions integration-tests/tests/src/tests/sync/flexible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ describe("Flexible sync", function () {
expect((compensatingWrites[1].primaryKey as BSON.ObjectId).equals(person2Id)).to.be.true;
expect((compensatingWrites[2].primaryKey as BSON.ObjectId).equals(dogId)).to.be.true;

expect(compensatingWrites[0].objectName).to.equal(Person.name);
expect(compensatingWrites[1].objectName).to.equal(Person.name);
expect(compensatingWrites[2].objectName).to.equal(Dog.name);
expect(compensatingWrites[0].objectName).to.equal("Person");
expect(compensatingWrites[1].objectName).to.equal("Person");
expect(compensatingWrites[2].objectName).to.equal("Dog");
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved

expect(compensatingWrites[0].reason).to.contain("object is outside of the current query view");
expect(compensatingWrites[1].reason).to.contain("object is outside of the current query view");
Expand Down Expand Up @@ -591,7 +591,7 @@ describe("Flexible sync", function () {

it("has an objectType", function (this: RealmContext) {
const { sub } = addSubscriptionForPerson(this.realm);
expect(sub.objectType).to.equal(Person.name);
expect(sub.objectType).to.equal("Person");
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
});

it("has a default queryString", function (this: RealmContext) {
Expand Down Expand Up @@ -1152,13 +1152,13 @@ describe("Flexible sync", function () {

const subsCopy = [...subs];
expect(subsCopy[0].queryString).to.equal("age < 10");
expect(subsCopy[0].objectType).to.equal(Person.name);
expect(subsCopy[0].objectType).to.equal("Person");
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved

expect(subsCopy[1].queryString).to.equal("age > 20");
expect(subsCopy[1].objectType).to.equal(Person.name);
expect(subsCopy[1].objectType).to.equal("Person");
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved

expect(subsCopy[2].queryString).to.equal("age > 30");
expect(subsCopy[2].objectType).to.equal(Dog.name);
expect(subsCopy[2].objectType).to.equal("Dog");
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
});

it("handles multiple updates in multiple batches", async function (this: RealmContext) {
Expand All @@ -1178,13 +1178,13 @@ describe("Flexible sync", function () {

const subsCopy = [...subs];
expect(subsCopy[0].queryString).to.equal("age < 10");
expect(subsCopy[0].objectType).to.equal(Person.name);
expect(subsCopy[0].objectType).to.equal("Person");
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved

expect(subsCopy[1].queryString).to.equal("age > 20");
expect(subsCopy[1].objectType).to.equal(Person.name);
expect(subsCopy[1].objectType).to.equal("Person");
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved

expect(subsCopy[2].queryString).to.equal("age > 30");
expect(subsCopy[2].objectType).to.equal(Dog.name);
expect(subsCopy[2].objectType).to.equal("Dog");
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
});

// TODO: Enable test when we can find another way of triggering a `SubscriptionSetState.Error`.
Expand Down
Loading
Loading