Skip to content

feat: Detox simulator test runner #590

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

Merged
merged 34 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
20031a9
Added detox tests for ios.
Chriztiaan May 7, 2025
a0ba3b0
Merge branch 'main' into op-sqlite-tests
Chriztiaan May 7, 2025
9047ac1
Fixing Android test suite. Prepping for Github workflow.
Chriztiaan May 7, 2025
021746b
Testing Android emulator.
Chriztiaan May 8, 2025
decad66
Fixing detox setup.
Chriztiaan May 8, 2025
25354f5
typo
Chriztiaan May 8, 2025
5a1a8fd
Added tests pnpm android working directory
Chriztiaan May 8, 2025
01c0967
Specifying avd name to workflow avd name.
Chriztiaan May 8, 2025
41705fe
Slightly more lenient test timeout.
Chriztiaan May 12, 2025
063a59f
Cleanup readme, removed prettier config. Applying prettier formatting…
Chriztiaan May 12, 2025
ae54fd4
Updated readme.
Chriztiaan May 12, 2025
0377d5f
Merged simulator/emulator tests into single workflow file.
Chriztiaan May 12, 2025
ceae348
Rejecting pending read/write operations when the database is closed f…
Chriztiaan May 12, 2025
fb97273
Merge branch 'main' into op-sqlite-tests
Chriztiaan May 12, 2025
d58eecf
Fixed typo in workflow.
Chriztiaan May 12, 2025
fd87b12
Typos.
Chriztiaan May 12, 2025
979d0a4
Added comlink to include list to stabilize web tests.
Chriztiaan May 12, 2025
a56e8c0
Revert lock file.
Chriztiaan May 12, 2025
e86c48d
Fewer executions in writeLock test.
Chriztiaan May 12, 2025
e70b962
Caching derived data for iOS build.
Chriztiaan May 15, 2025
a3ea29b
Make closing OPSQlite adapter async
stevensJourney May 19, 2025
b98a193
Add `await` to close test. Test CI command optimisation.
stevensJourney May 19, 2025
1924c86
Switching to new gradle action. Added changeset for close change.
Chriztiaan May 19, 2025
b7f80f5
Merge branch 'op-sqlite-tests' of github.com:powersync-ja/powersync-j…
Chriztiaan May 19, 2025
6e70eb7
Merge branch 'main' into op-sqlite-tests
Chriztiaan May 19, 2025
a028764
Referring to runner tool's Derived data location.
Chriztiaan May 22, 2025
50ba5e9
Different DerivedData location.
Chriztiaan May 22, 2025
4ca417c
Merge branch 'main' into op-sqlite-tests
Chriztiaan May 26, 2025
b79b970
Only running sim/emu tests if there are changes made to common or pow…
Chriztiaan May 26, 2025
5fecdd3
Added `await db.init()` call.
Chriztiaan May 26, 2025
2852194
Trying to cache derived data for iOS again.
Chriztiaan May 27, 2025
35ec382
Merge branch 'main' into op-sqlite-tests
Chriztiaan May 28, 2025
be0069d
Longer waiting indicator timeout for tests to finish.
Chriztiaan May 28, 2025
c38064c
Merge branch 'op-sqlite-tests' of github.com:powersync-ja/powersync-j…
Chriztiaan May 28, 2025
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
5 changes: 5 additions & 0 deletions .changeset/khaki-bottles-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/op-sqlite': patch
---

Rejecting pending read/write operations when the database is closed.
5 changes: 5 additions & 0 deletions .changeset/light-oranges-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/op-sqlite': minor
---

`close()` is now async, which allows clients to use it with `await`.
205 changes: 205 additions & 0 deletions .github/workflows/test-simulators.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Ensures certain packages work on simulators
name: Test Simulators/Emulators
on:
pull_request: # triggered for any PR updates (including new pushes to PR branch)

jobs:
check-changes:
name: Check for relevant changes
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changes
id: check
run: |
git fetch origin ${{ github.base_ref }}
if git diff --quiet origin/${{ github.base_ref }} -- packages/common packages/powersync-op-sqlite; then
echo "should_run=false" >> $GITHUB_OUTPUT
else
echo "should_run=true" >> $GITHUB_OUTPUT
fi

test-android:
name: Test Android
needs: check-changes
if: ${{ needs.check-changes.outputs.should_run == 'true' }}
runs-on: ubuntu-xl
env:
AVD_NAME: ubuntu-avd-x86_64-31
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: AVD Cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-31

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'adopt'
cache: 'gradle'

- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 9
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build:packages

- name: Setup Detox build framework cache
working-directory: ./tools/powersynctests
run: |
pnpx detox clean-framework-cache && pnpx detox build-framework-cache

- name: Initialize Android Folder
run: mkdir -p ~/.android/avd

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2.28.0
with:
api-level: 31
force-avd-creation: false
target: google_apis
arch: x86_64
disable-animations: false
avd-name: $AVD_NAME
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
script: echo "Generated AVD snapshot for caching."

- name: Android Emulator Build
working-directory: ./tools/powersynctests
run: pnpx detox build --configuration android.emu.release

- name: Run connected Android tests
uses: ReactiveCircus/android-emulator-runner@v2.28.0
with:
api-level: 31
target: google_apis
arch: x86_64
avd-name: $AVD_NAME
script: cd tools/powersynctests && pnpx detox test --configuration android.emu.release --headless
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true

test-ios:
name: Test iOS
needs: check-changes
if: ${{ needs.check-changes.outputs.should_run == 'true' }}
runs-on: macOS-15

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: CocoaPods Cache
uses: actions/cache@v3
id: cocoapods-cache
with:
path: |
tools/powersynctests/ios/Pods/*
key: ${{ runner.os }}-${{ hashFiles('tools/powersynctests/ios/Podfile.lock') }}

- name: Cache Xcode Derived Data
uses: actions/cache@v3
with:
path: |
tools/powersynctests/ios/build/*
key: xcode-derived-${{ runner.os }}-${{ hashFiles('tools/powersynctests/ios/Podfile.lock') }}
restore-keys: |
xcode-derived-${{ runner.os }}-

- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 9
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build:packages

- name: Install Detox dependencies
run: |
brew tap wix/brew
brew install applesimutils
npm install -g detox-cli
detox clean-framework-cache && detox build-framework-cache

- name: Install CocoaPods dependencies
working-directory: tools/powersynctests/ios
run: pod install

- name: iOS Simulator Build
working-directory: ./tools/powersynctests
run: pnpx detox build --configuration ios.sim.release

- name: iOS Simulator Test
working-directory: ./tools/powersynctests
run: pnpx detox test --configuration ios.sim.release --cleanup
32 changes: 25 additions & 7 deletions packages/powersync-op-sqlite/src/db/OPSqliteAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
import { ANDROID_DATABASE_PATH, getDylibPath, IOS_LIBRARY_PATH, open, type DB } from '@op-engineering/op-sqlite';
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
import Lock from 'async-lock';
import { OPSQLiteConnection } from './OPSQLiteConnection';
import { Platform } from 'react-native';
import { OPSQLiteConnection } from './OPSQLiteConnection';
import { SqliteOptions } from './SqliteOptions';

/**
Expand Down Expand Up @@ -32,6 +32,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
protected writeConnection: OPSQLiteConnection | null;

private readQueue: Array<() => void> = [];
private abortController: AbortController;

constructor(protected options: OPSQLiteAdapterOptions) {
super();
Expand All @@ -40,6 +41,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
this.locks = new Lock();
this.readConnections = null;
this.writeConnection = null;
this.abortController = new AbortController();
this.initialized = this.init();
}

Expand Down Expand Up @@ -153,11 +155,14 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
}
}

close() {
this.initialized.then(() => {
this.writeConnection!.close();
this.readConnections!.forEach((c) => c.connection.close());
});
async close() {
await this.initialized;
// Abort any pending operations
this.abortController.abort();
this.readQueue = [];

this.writeConnection!.close();
this.readConnections!.forEach((c) => c.connection.close());
}

async readLock<T>(fn: (tx: OPSQLiteConnection) => Promise<T>, options?: DBLockOptions): Promise<T> {
Expand Down Expand Up @@ -203,17 +208,30 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement

return new Promise(async (resolve, reject) => {
try {
// Set up abort signal listener
const abortListener = () => {
reject(new Error('Database connection was closed'));
};
this.abortController.signal.addEventListener('abort', abortListener);

await this.locks
.acquire(
LockType.WRITE,
async () => {
// Check if operation was aborted before executing
if (this.abortController.signal.aborted) {
reject(new Error('Database connection was closed'));
}
resolve(await fn(this.writeConnection!));
},
{ timeout: options?.timeoutMs }
)
.then(() => {
// flush updates once a write lock has been released
this.writeConnection!.flushUpdates();
})
.finally(() => {
this.abortController.signal.removeEventListener('abort', abortListener);
});
} catch (ex) {
reject(ex);
Expand Down
Loading