Skip to content

Commit

Permalink
Test on Android using "release" configuration (#6769)
Browse files Browse the repository at this point in the history
* Fixing react-native dependency

* Upgrading RNTA

* Adding an NPM script to attach logcat

* Bundling and running Android app in release mode in CI

* Fixed the package lock

* Uninstalling Android app

* Update build.gradle to pass additional cpp flags

* Using strings instead of class-names which might change when minified

* Upgrade mocha-remote to fix error reporting in release build

* Disabling minification to stabilize error messages

* Apply suggestions from code review

Co-authored-by: LJ <[email protected]>

---------

Co-authored-by: LJ <[email protected]>
  • Loading branch information
kraenhansen and elle-j committed Jul 5, 2024
1 parent 92fdeb6 commit 7b6a79b
Show file tree
Hide file tree
Showing 11 changed files with 901 additions and 290 deletions.
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
- 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
- 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
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
# 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",
"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.schema.name);
expect(compensatingWrites[1].objectName).to.equal(Person.schema.name);
expect(compensatingWrites[2].objectName).to.equal(Dog.schema.name);

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.schema.name);
});

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.schema.name);

expect(subsCopy[1].queryString).to.equal("age > 20");
expect(subsCopy[1].objectType).to.equal(Person.name);
expect(subsCopy[1].objectType).to.equal(Person.schema.name);

expect(subsCopy[2].queryString).to.equal("age > 30");
expect(subsCopy[2].objectType).to.equal(Dog.name);
expect(subsCopy[2].objectType).to.equal(Dog.schema.name);
});

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.schema.name);

expect(subsCopy[1].queryString).to.equal("age > 20");
expect(subsCopy[1].objectType).to.equal(Person.name);
expect(subsCopy[1].objectType).to.equal(Person.schema.name);

expect(subsCopy[2].queryString).to.equal("age > 30");
expect(subsCopy[2].objectType).to.equal(Dog.name);
expect(subsCopy[2].objectType).to.equal(Dog.schema.name);
});

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

0 comments on commit 7b6a79b

Please sign in to comment.