Skip to content

Commit 379c24b

Browse files
committedDec 20, 2019
Test transaction parallelism
1 parent 3a08574 commit 379c24b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎tests/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,31 @@ t('Transaction succeeds on uncaught savepoint', async() => {
168168
return [2, (await sql`select count(1) from test`)[0].count]
169169
}, () => sql`drop table test`)
170170

171+
t('Parallel transactions', async() => {
172+
await sql`create table test (a int)`
173+
return ['11', (await Promise.all([
174+
sql.begin(sql => sql`select 1`),
175+
sql.begin(sql => sql`select 1`),
176+
])).map(x => x.count).join('')]
177+
}, () => sql`drop table test`)
178+
179+
t('Transaction waits', async() => {
180+
await sql`create table test (a int)`
181+
await sql.begin(async sql => {
182+
await sql`insert into test values(1)`
183+
await sql.savepoint(async sql => {
184+
await sql`insert into test values(2)`
185+
throw new Error('please rollback')
186+
}).catch(() => { /* ignore */ })
187+
await sql`insert into test values(3)`
188+
})
189+
190+
return ['11', (await Promise.all([
191+
sql.begin(sql => sql`select 1`),
192+
sql.begin(sql => sql`select 1`),
193+
])).map(x => x.count).join('')]
194+
}, () => sql`drop table test`)
195+
171196
t('Helpers in Transaction', async() => {
172197
return [1, (await sql.begin(async sql =>
173198
await sql`select ${ sql({ x: 1 }) }`

0 commit comments

Comments
 (0)