mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
git-subtree-dir: packages/pg-query-stream git-subtree-mainline: cccf84e14b3281b753e1baab7bc194aaac5024a8 git-subtree-split: 9ced05e8aab65f3fdf1a67add87bfc9035e487e8
33 lines
944 B
JavaScript
33 lines
944 B
JavaScript
var pg = require('pg')
|
|
var QueryStream = require('../')
|
|
describe('end semantics race condition', function () {
|
|
before(function (done) {
|
|
var 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) {
|
|
var client1 = new pg.Client()
|
|
client1.connect()
|
|
var client2 = new pg.Client()
|
|
client2.connect()
|
|
|
|
var qr = new QueryStream('INSERT INTO p DEFAULT VALUES RETURNING id')
|
|
client1.query(qr)
|
|
var 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)
|
|
})
|
|
})
|
|
})
|
|
})
|