Skip to content

Commit b3efdb2

Browse files
committed
...
1 parent cf4d685 commit b3efdb2

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

test/node/src/cancellation.test.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,46 @@ for (const dialect of DIALECTS) {
5858
})
5959

6060
it('should throw an abort error when aborted during query execution', async () => {
61-
const sleepQuery = (
61+
const writeQuery = ctx.db
62+
.insertInto('person')
63+
.values({ gender: sql.lit('woah') as never })
64+
65+
const delayedQuery = (
6266
{
63-
postgres: sql`select pg_sleep(300)`,
64-
mysql: sql`select sleep(300)`,
65-
mssql: sql`waitfor delay '00:05:00.000'`,
67+
postgres: sql`select pg_sleep(1); ${writeQuery};`,
68+
mysql: sql`select sleep(1); ${writeQuery};`,
69+
mssql: sql`waitfor delay '00:00:01.000'; ${writeQuery};`,
6670
sqlite: sql`WITH RECURSIVE timer(i) AS (
6771
SELECT 1
6872
UNION ALL
6973
SELECT i + 1 FROM timer WHERE i < 10000000
7074
)
71-
SELECT COUNT(*) FROM timer;`,
75+
SELECT COUNT(*) FROM timer; ${writeQuery};`,
7276
} as const satisfies Record<BuiltInDialect, RawBuilder<any>>
7377
)[dialect]
7478

7579
const abortController = new AbortController()
7680
setTimeout(10).then(() => abortController.abort())
7781

7882
await expect(
79-
sleepQuery.execute(ctx.db, { abortSignal: abortController.signal }),
83+
delayedQuery.execute(ctx.db, { abortSignal: abortController.signal }),
8084
)
8185
.to.eventually.be.rejectedWith(AbortError)
8286
.and.satisfies(
8387
(error: AbortError) =>
8488
error.reason === 'aborted during query execution',
8589
)
90+
91+
// this checks the write after the sleep query was not executed due to the abort.
92+
await expect(
93+
ctx.db
94+
.selectFrom('person')
95+
.where('gender', '=', 'woah' as never)
96+
.select(ctx.db.fn.countAll().as('count'))
97+
.executeTakeFirstOrThrow(),
98+
).to.eventually.satisfy(
99+
(result: { count: unknown }) => Number(result.count) === 0,
100+
)
86101
})
87102

88103
it('should throw an abort error when aborted during result transformation', async () => {

test/node/src/test-setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const MYSQL_CONFIG: PoolOptions = {
140140
bigNumberStrings: true,
141141

142142
connectionLimit: POOL_SIZE,
143+
multipleStatements: true,
143144
}
144145

145146
const MSSQL_CONFIG: ConnectionConfiguration = {

0 commit comments

Comments
 (0)