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

Add Android Instrumentation Tests to CI #41

Merged
merged 42 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3ac13d5
add a github action for running the android tests
nplasterer May 9, 2023
33e2be8
drop to api level 29
nplasterer May 9, 2023
1891ed1
specify the working directory
nplasterer May 9, 2023
91d0f9a
a few tweaks to where the action is being called
nplasterer May 9, 2023
69ff6e3
another try
nplasterer May 9, 2023
bce2a6f
give it more time to load
nplasterer May 10, 2023
ce6c15f
small tweak to the github action
nplasterer May 10, 2023
0964875
another action try
nplasterer May 10, 2023
0e17ebf
more github action trys
nplasterer May 10, 2023
23068ac
try targeting 33
nplasterer May 10, 2023
8140a61
another try on the emulator type
nplasterer May 10, 2023
7283435
is this the correct configuration
nplasterer May 11, 2023
5f60758
step down api level
nplasterer May 12, 2023
92fae7b
back to the beginning
nplasterer May 12, 2023
3dbf97a
disable animations
nplasterer May 12, 2023
ab9cc23
try
nplasterer May 15, 2023
eee6a2d
magic combo
nplasterer May 16, 2023
763ec62
run tests
nplasterer May 18, 2023
2dbc03e
run test on this branch
May 22, 2023
3540ec9
try cache clean
May 22, 2023
2129f61
force install xmtp and ethers for docker
May 22, 2023
92f1d41
force install react native cli
May 22, 2023
36acf4d
cache clean npm
May 22, 2023
d74594a
force install dockerfile
May 22, 2023
7bd74ad
remove docker for now
May 22, 2023
f5fc2d6
add variant release
May 22, 2023
5a7f11b
install react native cli
May 22, 2023
4b67b1d
globally install react native cli
May 22, 2023
08b31bd
run-android in the example directory
May 22, 2023
4a78ae3
use npx
May 22, 2023
51d66ae
add back working dir
May 22, 2023
f8119c9
so close. switch working directory again
May 22, 2023
1c9f494
it needs to use the example dir
May 22, 2023
1c3c11b
please work and change directories
May 22, 2023
57918d3
try adding package.json to dockerfile
May 23, 2023
a7c0298
Revert "try adding package.json to dockerfile"
May 23, 2023
2e91522
install git in dockerfile
May 23, 2023
fb5190d
add back docker steps
May 23, 2023
9efa2f0
save changes while i investigate locally
May 23, 2023
8278d92
revert view finder timeout to ten sec
May 23, 2023
40e002a
add android test orchestrator
May 24, 2023
c77bb89
Revert "revert view finder timeout to ten sec"
May 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/androidTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Android Tests
on:
push:
branches:
- main
pull_request:

env:
GPR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPR_USER: ${{ secrets.GITHUB_ACTOR }}

defaults:
run:
working-directory: ./example

jobs:
android-tests:
name: Android Tests
runs-on: macos-latest
steps:
- name: Checkout project sources
uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Setup Node.js
uses: actions/setup-node@v3

- name: Install dependencies
run: npm i --force

- name: Install React Native CLI
run: npm i -g react-native-cli --force

- name: Install docker
run: |
mkdir -p ~/.docker/machine/cache
curl -Lo ~/.docker/machine/cache/boot2docker.iso https://github.com/boot2docker/boot2docker/releases/download/v19.03.12/boot2docker.iso
brew install docker docker-compose

- name: Start colima
run: |
# Docker engine is no longer available because of licensing
# Alternative Colima is part of the github macOS runner
colima start
# Ensure colima is configured for later user
echo "DOCKER_HOST=unix://$HOME/.colima/default/docker.sock" >> $GITHUB_ENV
# Verify Docker
docker ps

- name: Start local test server
run: docker-compose -p xmtp -f dev/local/docker-compose.yml up -d

- name: Gradle Run Integration Tests
uses: reactivecircus/android-emulator-runner@v2
with:
working-directory: ./example
api-level: 29
script: |
react-native run-android
sleep 15
cd android && ./gradlew connectedCheck
elisealix22 marked this conversation as resolved.
Show resolved Hide resolved

- name: Stop local test server
run: docker-compose -p xmtp -f dev/local/docker-compose.yml down
8 changes: 7 additions & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,15 @@ android {
versionName "1.0.0"
// For Espresso
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
testInstrumentationRunnerArguments useTestStorageService: 'true'
testInstrumentationRunnerArgument('useTestStorageService', 'true')
// The following argument makes the Android Test Orchestrator run its
// "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests.
testInstrumentationRunnerArgument('clearPackageData', 'true')
}

testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
managedDevices {
devices {
// run with ../gradlew nexusOneApi30DebugAndroidTest
Expand Down Expand Up @@ -264,6 +269,7 @@ dependencies {
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5"
androidTestUtil "androidx.test.services:test-services:1.4.2"
androidTestUtil 'androidx.test:orchestrator:1.4.2'
}

apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.util.concurrent.TimeoutException

object EspressoViewFinder {
private const val CHECK_INTERVAL = 50L
private const val TIMEOUT_MS = 10 * 1000L
private const val TIMEOUT_MS = 15 * 1000L
elisealix22 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Waits for the view referenced in [viewMatcher] to become visible, with a timeout of [timeOut]. If it
Expand Down
39 changes: 39 additions & 0 deletions example/dev/local/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "3.8"
services:
wakunode:
image: xmtp/node-go
platform: linux/amd64
environment:
- GOWAKU-NODEKEY=8a30dcb604b0b53627a5adc054dbf434b446628d4bd1eccc681d223f0550ce67
command:
- --ws
- --store
- --message-db-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable
- --message-db-reader-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable
- --lightpush
- --filter
- --ws-port=9001
- --wait-for-db=30s
- --api.authn.enable
ports:
- 9001:9001
- 5555:5555 # http message API
- 5556:5556 # grpc message API
depends_on:
- db
healthcheck:
test: ["CMD", "lsof", "-i", ":5556"]
interval: 3s
timeout: 10s
retries: 5
db:
image: postgres:13
environment:
POSTGRES_PASSWORD: xmtp
js:
restart: always
depends_on:
wakunode:
condition: service_healthy
build: ./test

7 changes: 7 additions & 0 deletions example/dev/local/test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:19-alpine

WORKDIR /code
ADD script.js script.js
RUN apk update && apk add git
RUN npm install @xmtp/xmtp-js ethers
CMD ["node", "script.js"]
35 changes: 35 additions & 0 deletions example/dev/local/test/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
let Client = require("@xmtp/xmtp-js").Client;
let Wallet = require("ethers").Wallet;

console.log("NODE VERSION", process.version);

// 0xf4BF19Ed562651837bc11ff975472ABd239D35B5
const keyBytes = [
80, 7, 53, 52, 122, 163, 75, 130, 199, 86, 216, 14, 29, 2, 255, 71, 121, 51,
165, 3, 208, 178, 193, 207, 223, 217, 75, 247, 84, 78, 204, 3,
];

async function checkAll() {
const wallet = new Wallet(keyBytes);
const client = await Client.create(wallet, {
apiUrl: "http://wakunode:5555",
});

console.log("Listening…");

try {
for await (const message of await client.conversations.streamAllMessages()) {
if (message.senderAddress === wallet.address) {
continue;
}

await message.conversation.send("HI " + message.senderAddress);
console.log(`Replied to ${message.senderAddress}`);
}
} catch (e) {
console.info(`Error:`, e);
await checkAll();
}
}

checkAll().then(() => console.log("Done"));