Skip to content

OP-SQLite async iterator tests #615

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/test-simulators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
id: check
run: |
git fetch origin ${{ github.base_ref }}
if git diff --quiet origin/${{ github.base_ref }} -- packages/common packages/powersync-op-sqlite; then
if git diff --quiet origin/${{ github.base_ref }} -- packages/common packages/powersync-op-sqlite tools/powersynctests; then
echo "should_run=false" >> $GITHUB_OUTPUT
else
echo "should_run=true" >> $GITHUB_OUTPUT
Expand Down
428 changes: 211 additions & 217 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions tools/powersynctests/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
'@babel/plugin-transform-async-generator-functions',
'@babel/plugin-transform-class-static-block',
[
'module-resolver',
{
alias: {
stream: 'stream-browserify',
},
},
],
],
stream: 'stream-browserify'
}
}
]
]
};
10 changes: 5 additions & 5 deletions tools/powersynctests/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PODS:
- hermes-engine (0.78.0):
- hermes-engine/Pre-built (= 0.78.0)
- hermes-engine/Pre-built (0.78.0)
- op-sqlite (11.4.9):
- op-sqlite (11.4.8):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -31,7 +31,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- powersync-op-sqlite (0.5.4):
- powersync-op-sqlite (0.6.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1829,8 +1829,8 @@ SPEC CHECKSUMS:
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
glog: eb93e2f488219332457c3c4eafd2738ddc7e80b8
hermes-engine: b417d2b2aee3b89b58e63e23a51e02be91dc876d
op-sqlite: d07002ecca5c39575deb7c4abd9e5310da6aa07d
powersync-op-sqlite: ce90a0e44924deea3901d06892d2d687e6eaf0c1
op-sqlite: 060f3d3902e6a49657051505a9c93f2688ef4943
powersync-op-sqlite: f2cacb147e29212f3f76ce44f50d7cac20949a5b
powersync-sqlite-core: ef06642c8110680fcddce8a8c0dd2696daaf672d
RCT-Folly: 36fe2295e44b10d831836cc0d1daec5f8abcf809
RCTDeprecation: b2eecf2d60216df56bc5e6be5f063826d3c1ee35
Expand Down Expand Up @@ -1897,4 +1897,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: a15b54e8d191759ce7fcccb262b8753851ec9fde

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
2 changes: 2 additions & 0 deletions tools/powersynctests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"start": "react-native start"
},
"dependencies": {
"@azure/core-asynciterator-polyfill": "^1.0.2",
"@op-engineering/op-sqlite": "^11.4.8",
"@powersync/common": "workspace:*",
"@powersync/op-sqlite": "workspace:*",
Expand All @@ -30,6 +31,7 @@
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/plugin-transform-async-generator-functions": "^7.27.1",
"@babel/plugin-transform-class-static-block": "^7.26.0",
"@babel/preset-env": "^7.25.3",
"@babel/runtime": "^7.25.0",
Expand Down
6 changes: 3 additions & 3 deletions tools/powersynctests/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @format
*/

import '@azure/core-asynciterator-polyfill';
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, useColorScheme } from 'react-native';

Expand All @@ -17,7 +17,7 @@ function App(): React.JSX.Element {
const isDarkMode = useColorScheme() === 'dark';

const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter
};

const [] = React.useState(registerBaseTests());
Expand All @@ -40,7 +40,7 @@ function App(): React.JSX.Element {
/>
<ScrollView style={backgroundStyle}>
{/* <PowerSyncIndicator /> */}
{rootSuite.suites.map(suite => (
{rootSuite.suites.map((suite) => (
<SuitWidget key={suite.title} suit={suite} />
))}
</ScrollView>
Expand Down
43 changes: 43 additions & 0 deletions tools/powersynctests/src/tests/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,49 @@ export function registerBaseTests() {
await watched;
});

it('Should reflect writeTransaction updates on read connections (iterator)', async () => {
const watched = new Promise<void>(async (resolve) => {
for await (const result of db.watch('SELECT COUNT(*) as count FROM users', [])) {
if (result.rows?.item(0).count == 1) {
resolve();
}
}
});

await db.writeTransaction(async (tx) => {
return createTestUser(tx);
});

// The watched query should have updated
await watched;
});

it('Should throw for async iterator watch errors', async () => {
let error: Error | undefined;
try {
// The table here does not exist, so it should throw an error
for await (const result of db.watch('SELECT COUNT(*) as count FROM faketable', [])) {
}
} catch (ex) {
error = ex as Error;
}

expect(error!.message).to.include('no such table: faketable');
});

it('Should throw for async iterator invalid query errors', async () => {
let error: Error | undefined;
try {
// Invalid SQL
for await (const result of db.watch('invalidsyntax', [])) {
}
} catch (ex) {
error = ex as Error;
}

expect(error!.message).to.include('sqlite query error');
});

it('Should reflect writeLock updates on read connections ', async () => {
const numberOfUsers = 1000;

Expand Down