Skip to content

Commit e70477b

Browse files
Fix failing test due to lock timeout
1 parent c7b3031 commit e70477b

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

packages/web/tests/uploads.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import p from 'p-defer';
33
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
44
import { ConnectedDatabaseUtils, generateConnectedDatabase } from './stream.test';
55

6+
// Don't want to actually export the warning string from the package
7+
const PARTIAL_WARNING = 'Potentially previously uploaded CRUD entries are still present';
8+
69
describe('CRUD Uploads', () => {
710
let connectedUtils: ConnectedDatabaseUtils;
811
const logger = Logger.get('crud-logger');
@@ -13,11 +16,7 @@ describe('CRUD Uploads', () => {
1316
connectedUtils = await generateConnectedDatabase({
1417
powerSyncOptions: {
1518
logger,
16-
/**
17-
* The timeout here is set to longer than the default test timeout
18-
* A retry wil cause tests to fail.
19-
*/
20-
crudUploadThrottleMs: 10_000,
19+
crudUploadThrottleMs: 1_000,
2120
flags: {
2221
enableMultiTabs: false
2322
}
@@ -52,11 +51,7 @@ describe('CRUD Uploads', () => {
5251

5352
await vi.waitFor(
5453
() => {
55-
expect(
56-
loggerSpy.mock.calls.find((logArgs) =>
57-
logArgs[0].includes('Potentially previously uploaded CRUD entries are still present')
58-
)
59-
).exist;
54+
expect(loggerSpy.mock.calls.find((logArgs) => logArgs[0].includes(PARTIAL_WARNING))).exist;
6055
},
6156
{
6257
timeout: 500
@@ -66,15 +61,15 @@ describe('CRUD Uploads', () => {
6661

6762
it('should immediately upload sequential transactions', async () => {
6863
const { powersync, uploadSpy } = connectedUtils;
64+
const loggerSpy = vi.spyOn(logger, 'warn');
65+
6966
const deferred = p();
7067

7168
uploadSpy.mockImplementation(async (db) => {
72-
// This upload method does not perform an upload
7369
const nextTransaction = await db.getNextCrudTransaction();
7470
if (!nextTransaction) {
7571
return;
7672
}
77-
7873
// Mockingly delete the crud op in order to progress through the CRUD queue
7974
for (const op of nextTransaction.crud) {
8075
await db.execute(`DELETE FROM ps_crud WHERE id = ?`, [op.clientId]);
@@ -111,5 +106,7 @@ describe('CRUD Uploads', () => {
111106
timeout: 5_000
112107
}
113108
);
109+
110+
expect(loggerSpy.mock.calls.find((logArgs) => logArgs[0].includes(PARTIAL_WARNING))).toBeUndefined;
114111
});
115112
});

0 commit comments

Comments
 (0)