mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Update pg-cursor
pg-cursor no longer returns the empty array 'done' signal to the callback until the cursor recieves a readyForQuery message. This means pg-query-stream will not emit 'close' or 'end' events until the server is __truly__ ready for the next query. This fixes some race-conditions where some queries are triggered off of the `end` event of the query-stream closes #3
This commit is contained in:
parent
0a7da37ab7
commit
1961125476
@ -33,6 +33,6 @@
|
||||
"mocha": "~1.17.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"pg-cursor": "~0.1.2"
|
||||
"pg-cursor": "0.1.3"
|
||||
}
|
||||
}
|
||||
|
||||
32
test/issue-3.js
Normal file
32
test/issue-3.js
Normal file
@ -0,0 +1,32 @@
|
||||
var pg = require('pg.js')
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user