Skip to content

Commit

Permalink
Fix failing test due to lock timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Sep 20, 2024
1 parent c7b3031 commit e70477b
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/web/tests/uploads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import p from 'p-defer';
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { ConnectedDatabaseUtils, generateConnectedDatabase } from './stream.test';

// Don't want to actually export the warning string from the package
const PARTIAL_WARNING = 'Potentially previously uploaded CRUD entries are still present';

describe('CRUD Uploads', () => {
let connectedUtils: ConnectedDatabaseUtils;
const logger = Logger.get('crud-logger');
Expand All @@ -13,11 +16,7 @@ describe('CRUD Uploads', () => {
connectedUtils = await generateConnectedDatabase({
powerSyncOptions: {
logger,
/**
* The timeout here is set to longer than the default test timeout
* A retry wil cause tests to fail.
*/
crudUploadThrottleMs: 10_000,
crudUploadThrottleMs: 1_000,
flags: {
enableMultiTabs: false
}
Expand Down Expand Up @@ -52,11 +51,7 @@ describe('CRUD Uploads', () => {

await vi.waitFor(
() => {
expect(
loggerSpy.mock.calls.find((logArgs) =>
logArgs[0].includes('Potentially previously uploaded CRUD entries are still present')
)
).exist;
expect(loggerSpy.mock.calls.find((logArgs) => logArgs[0].includes(PARTIAL_WARNING))).exist;
},
{
timeout: 500
Expand All @@ -66,15 +61,15 @@ describe('CRUD Uploads', () => {

it('should immediately upload sequential transactions', async () => {
const { powersync, uploadSpy } = connectedUtils;
const loggerSpy = vi.spyOn(logger, 'warn');

const deferred = p();

uploadSpy.mockImplementation(async (db) => {
// This upload method does not perform an upload
const nextTransaction = await db.getNextCrudTransaction();
if (!nextTransaction) {
return;
}

// Mockingly delete the crud op in order to progress through the CRUD queue
for (const op of nextTransaction.crud) {
await db.execute(`DELETE FROM ps_crud WHERE id = ?`, [op.clientId]);
Expand Down Expand Up @@ -111,5 +106,7 @@ describe('CRUD Uploads', () => {
timeout: 5_000
}
);

expect(loggerSpy.mock.calls.find((logArgs) => logArgs[0].includes(PARTIAL_WARNING))).toBeUndefined;
});
});

0 comments on commit e70477b

Please sign in to comment.