Skip to content

Commit 4e9faee

Browse files
Merge pull request #9 from powersync-ja/fix/dependencies
[Fix] Missing dependencies
2 parents ad74fd7 + 2802916 commit 4e9faee

File tree

8 files changed

+73
-25
lines changed

8 files changed

+73
-25
lines changed

.changeset/funny-guests-walk.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/react-native-quick-sqlite': patch
3+
---
4+
5+
Fixed: Missing dependency for `uuid` and race condition where ommitting `await` on some lock/transaction operations could deadlock the application's main thread.

cpp/ConnectionState.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ void ConnectionState::doWork() {
9292
++threadBusy;
9393
task(connection);
9494
--threadBusy;
95+
// Need to notify in order for waitFinished to be updated when
96+
// the queue is empty and not busy
97+
workQueueConditionVariable.notify_all();
9598
}
96-
workQueueConditionVariable.notify_all();
9799
}
98100

99101
void ConnectionState::waitFinished() {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
]
8282
},
8383
"dependencies": {
84-
"lodash": "^4.17.21"
84+
"lodash": "^4.17.21",
85+
"uuid": "3.4.0"
8586
}
8687
}

tests/App.tsx

+26-7
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,38 @@ const TEST_SERVER_URL = 'http://localhost:4243/results';
1010
export default function App() {
1111
const [results, setResults] = useState<any>([]);
1212

13-
useEffect(() => {
14-
console.log('Running Tests:');
13+
const executeTests = React.useCallback(async () => {
1514
setResults([]);
16-
runTests(registerBaseTests).then((results) => {
15+
16+
try {
17+
const results = await runTests(registerBaseTests);
18+
console.log(JSON.stringify(results, null, '\t'));
19+
setResults(results);
1720
// Send results to host server
18-
fetch(TEST_SERVER_URL, {
21+
await fetch(TEST_SERVER_URL, {
1922
method: 'POST',
2023
headers: { 'Content-Type': 'application/json' },
2124
body: JSON.stringify(results)
2225
});
23-
console.log(JSON.stringify(results, null, '\t'));
24-
setResults(results);
25-
});
26+
} catch (ex) {
27+
console.error(ex);
28+
// Send results to host server
29+
fetch(TEST_SERVER_URL, {
30+
method: 'POST',
31+
headers: { 'Content-Type': 'application/json' },
32+
body: JSON.stringify([
33+
{
34+
description: `Caught exception: ${ex}`,
35+
type: 'incorrect'
36+
}
37+
])
38+
});
39+
}
40+
}, []);
41+
42+
useEffect(() => {
43+
console.log('Running Tests:');
44+
executeTests();
2645
}, []);
2746

2847
return (

tests/tests/mocha/MochaRNAdapter.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const rootSuite = new Mocha.Suite('') as MochaTypes.Suite;
55
rootSuite.timeout(10 * 1000);
66

77
let mochaContext = rootSuite;
8+
89
let only = false;
910

1011
export const clearTests = () => {
@@ -14,20 +15,18 @@ export const clearTests = () => {
1415
only = false;
1516
};
1617

17-
export const it = (
18-
name: string,
19-
f: MochaTypes.Func | MochaTypes.AsyncFunc,
20-
): void => {
18+
export const it = (name: string, f: MochaTypes.Func | MochaTypes.AsyncFunc): void => {
2119
if (!only) {
22-
const test = new Mocha.Test(name, f);
20+
const test = new Mocha.Test(name, async () => {
21+
console.log(`Running ${name}`);
22+
// @ts-ignore
23+
return f();
24+
});
2325
mochaContext.addTest(test);
2426
}
2527
};
2628

27-
export const itOnly = (
28-
name: string,
29-
f: MochaTypes.Func | MochaTypes.AsyncFunc,
30-
): void => {
29+
export const itOnly = (name: string, f: MochaTypes.Func | MochaTypes.AsyncFunc): void => {
3130
clearTests();
3231
const test = new Mocha.Test(name, f);
3332
mochaContext.addTest(test);
@@ -36,11 +35,9 @@ export const itOnly = (
3635

3736
export const describe = (name: string, f: () => void): void => {
3837
const prevMochaContext = mochaContext;
39-
mochaContext = new Mocha.Suite(
40-
name,
41-
prevMochaContext.ctx,
42-
) as MochaTypes.Suite;
38+
mochaContext = new Mocha.Suite(name, prevMochaContext.ctx) as MochaTypes.Suite;
4339
prevMochaContext.addSuite(mochaContext);
40+
console.log(`Running ${name}`);
4441
f();
4542
mochaContext = prevMochaContext;
4643
};

tests/tests/sqlite/rawQueries.spec.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export function registerBaseTests() {
157157

158158
await db.writeTransaction(async (tx) => {
159159
await tx.execute('INSERT INTO "User" (id, name, age, networth) VALUES(?, ?, ?, ?)', [id, name, age, networth]);
160-
tx.commit();
160+
await tx.commit();
161161
});
162162

163163
const res = await db.execute('SELECT * FROM User');
@@ -176,6 +176,24 @@ export function registerBaseTests() {
176176

177177
await db.writeTransaction(async (tx) => {
178178
await tx.execute('INSERT INTO "User" (id, name, age, networth) VALUES(?, ?, ?, ?)', [id, name, age, networth]);
179+
await tx.rollback();
180+
});
181+
182+
const res = await db.execute('SELECT * FROM User');
183+
expect(res.rows?._array).to.eql([]);
184+
});
185+
186+
/**
187+
* The lock manager will attempt to free the connection lock
188+
* as soon as the callback resolves, but it should also
189+
* correctly await any queued work such as tx.rollback();
190+
*/
191+
it('Transaction, manual rollback, forgot await', async () => {
192+
const { id, name, age, networth } = generateUserInfo();
193+
194+
await db.writeTransaction(async (tx) => {
195+
await tx.execute('INSERT INTO "User" (id, name, age, networth) VALUES(?, ?, ?, ?)', [id, name, age, networth]);
196+
// Purposely forget await to this.
179197
tx.rollback();
180198
});
181199

tests/yarn.lock

+3-2
Original file line numberDiff line numberDiff line change
@@ -6017,9 +6017,10 @@ react-native-quick-base64@^2.0.5:
60176017
base64-js "^1.5.1"
60186018

60196019
react-native-quick-sqlite@./..:
6020-
version "0.0.1"
6020+
version "0.1.0"
60216021
dependencies:
60226022
lodash "^4.17.21"
6023+
uuid "3.4.0"
60236024

60246025
react-native-safe-area-context@^4.5.0:
60256026
version "4.7.3"
@@ -7127,7 +7128,7 @@ [email protected]:
71277128
resolved "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz"
71287129
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==
71297130

7130-
uuid@^3.3.2, uuid@^3.4.0:
7131+
uuid@3.4.0, uuid@^3.3.2, uuid@^3.4.0:
71317132
version "3.4.0"
71327133
resolved "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz"
71337134
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -6351,6 +6351,11 @@ [email protected]:
63516351
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
63526352
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==
63536353

6354+
6355+
version "3.4.0"
6356+
resolved "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
6357+
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
6358+
63546359
validate-npm-package-license@^3.0.1:
63556360
version "3.0.4"
63566361
resolved "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"

0 commit comments

Comments
 (0)