|
1 | 1 | import * as path from 'node:path'; |
2 | 2 | import { Worker } from 'node:worker_threads'; |
3 | 3 |
|
4 | | -import { vi, expect, test } from 'vitest'; |
5 | | -import { AppSchema, databaseTest, tempDirectoryTest } from './utils'; |
| 4 | +import { LockContext } from '@powersync/common'; |
| 5 | +import { randomUUID } from 'node:crypto'; |
| 6 | +import { expect, test, vi } from 'vitest'; |
6 | 7 | import { CrudEntry, CrudTransaction, PowerSyncDatabase } from '../lib'; |
7 | 8 | import { WorkerOpener } from '../lib/db/options'; |
8 | | -import { LockContext } from '@powersync/common'; |
| 9 | +import { AppSchema, databaseTest, tempDirectoryTest } from './utils'; |
9 | 10 |
|
10 | 11 | test('validates options', async () => { |
11 | 12 | await expect(async () => { |
@@ -203,3 +204,26 @@ databaseTest('getCrudTransactions', async ({ database }) => { |
203 | 204 | const remainingTransaction = await database.getNextCrudTransaction(); |
204 | 205 | expect(remainingTransaction?.crud).toHaveLength(15); |
205 | 206 | }); |
| 207 | + |
| 208 | +// This is not a SemVer check, but is basic enough to skip this test on older versions of Node.js |
| 209 | +tempDirectoryTest.skipIf(process.versions.node < '22.5.0')( |
| 210 | + 'should not present database is locked errors on startup', |
| 211 | + async ({ tmpdir }) => { |
| 212 | + for (let i = 0; i < 10; i++) { |
| 213 | + const database = new PowerSyncDatabase({ |
| 214 | + schema: AppSchema, |
| 215 | + database: { |
| 216 | + dbFilename: `${randomUUID()}.sqlite`, |
| 217 | + dbLocation: tmpdir, |
| 218 | + implementation: { |
| 219 | + type: 'node:sqlite' |
| 220 | + } |
| 221 | + } |
| 222 | + }); |
| 223 | + |
| 224 | + // This should not throw |
| 225 | + await database.waitForReady(); |
| 226 | + await database.close(); |
| 227 | + } |
| 228 | + } |
| 229 | +); |
0 commit comments