-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathissue-3.ts
33 lines (31 loc) · 950 Bytes
/
issue-3.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pg from 'pg'
import QueryStream from '../src'
describe('end semantics race condition', function () {
before(function (done) {
const client = new pg.Client()
client.connect()
client.on('drain', client.end.bind(client))
client.on('end', done)
client.query('create table IF NOT EXISTS p(id serial primary key)')
client.query('create table IF NOT EXISTS c(id int primary key references p)')
})
it('works', function (done) {
const client1 = new pg.Client()
client1.connect()
const client2 = new pg.Client()
client2.connect()
const qr = new QueryStream('INSERT INTO p DEFAULT VALUES RETURNING id')
client1.query(qr)
let id = null
qr.on('data', function (row) {
id = row.id
})
qr.on('end', function () {
client2.query('INSERT INTO c(id) VALUES ($1)', [id], function (err, rows) {
client1.end()
client2.end()
done(err)
})
})
})
})