Skip to content

Commit 09da5ef

Browse files
authored
Fix async interrupt tests timing out on Windows (#211)
Add a short delay before calling interrupt() in the Database.interrupt() and Statement.interrupt() tests to ensure the query is actively running on the tokio runtime. Without the delay, the interrupt flag can be set before sqlite3_step() starts, causing a race condition where the flag gets consumed without effect on Windows.
2 parents 7f95424 + 28636c4 commit 09da5ef

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

integration-tests/tests/async.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ test.serial("Database.interrupt()", async (t) => {
344344
const db = t.context.db;
345345
const stmt = await db.prepare("WITH RECURSIVE infinite_loop(n) AS (SELECT 1 UNION ALL SELECT n + 1 FROM infinite_loop) SELECT * FROM infinite_loop;");
346346
const fut = stmt.all();
347+
// Wait for the query to start executing on the tokio runtime before
348+
// interrupting, otherwise the interrupt flag may be set before the first
349+
// sqlite3_step() and get consumed without effect on some platforms.
350+
await new Promise(resolve => setTimeout(resolve, 100));
347351
db.interrupt();
348352
await t.throwsAsync(async () => {
349353
await fut;
@@ -359,6 +363,7 @@ test.serial("Statement.interrupt()", async (t) => {
359363
const db = t.context.db;
360364
const stmt = await db.prepare("WITH RECURSIVE infinite_loop(n) AS (SELECT 1 UNION ALL SELECT n + 1 FROM infinite_loop) SELECT * FROM infinite_loop;");
361365
const fut = stmt.all();
366+
await new Promise(resolve => setTimeout(resolve, 100));
362367
stmt.interrupt();
363368
await t.throwsAsync(async () => {
364369
await fut;

0 commit comments

Comments
 (0)