mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
fix to allow executing queries within the callback function of another query.
there was a timing issue with emiting the drain event
This commit is contained in:
parent
43cbd34a0a
commit
8d7ff353af
@ -88,7 +88,12 @@ p.pulseQueryQueue = function() {
|
||||
this.activeQuery = query;
|
||||
query.submit(this.connection);
|
||||
} else {
|
||||
this.emit('drain');
|
||||
var self = this;
|
||||
process.nextTick(function() {
|
||||
if(this.queryQueue.length <= 0) {
|
||||
this.emit('drain');
|
||||
}
|
||||
}.bind(this))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -4,7 +4,7 @@ var pg = require(__dirname + '/../../../lib');
|
||||
var connected = false
|
||||
var simpleCalled = false
|
||||
var preparedCalled = false
|
||||
|
||||
var nestedCalled = false
|
||||
pg.connect(helper.args, function(err, client) {
|
||||
connected = true
|
||||
assert.equal(err, null, "Failed to connect");
|
||||
@ -38,10 +38,19 @@ pg.connect(helper.args, function(err, client) {
|
||||
assert.equal(result.rows.pop().name, 'the beach boys');
|
||||
})
|
||||
})
|
||||
|
||||
test('executing nested queries', function() {
|
||||
client.query('select * FROM band', function(err, result) {
|
||||
client.query('select * FROM band', function(err, result2) {
|
||||
nestedCalled = true
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.ok(connected, 'never connected');
|
||||
assert.ok(nestedCalled, 'never called nested query')
|
||||
assert.ok(simpleCalled, 'query result callback was never called');
|
||||
assert.ok(preparedCalled, 'prepared callback was never called');
|
||||
})
|
||||
|
||||
@ -43,7 +43,9 @@ test("when all queries are sent", function() {
|
||||
test("after last query finishes", function() {
|
||||
con.emit('readyForQuery');
|
||||
test("emits drain", function() {
|
||||
assert.ok(raisedDrain);
|
||||
process.nextTick(function() {
|
||||
assert.ok(raisedDrain);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user