mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
added 'drain' event to client which fires after all pending queries
are done
This commit is contained in:
parent
d38a7f5ed7
commit
577f48f824
@ -67,11 +67,16 @@ p.connect = function() {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
p.pulseQueryQueue = function() {
|
||||
if(this.readyForQuery===true && this.queryQueue.length > 0) {
|
||||
this.readyForQuery = false;
|
||||
var query = this.queryQueue.shift();
|
||||
query.submit(this.connection);
|
||||
if(this.readyForQuery===true) {
|
||||
if(this.queryQueue.length > 0) {
|
||||
this.readyForQuery = false;
|
||||
var query = this.queryQueue.shift();
|
||||
query.submit(this.connection);
|
||||
} else {
|
||||
this.emit('drain');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
49
test/unit/client/query-queue-tests.js
Normal file
49
test/unit/client/query-queue-tests.js
Normal file
@ -0,0 +1,49 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
var con = new Connection({stream: "NO"});
|
||||
var client = new Client({connection:con});
|
||||
|
||||
|
||||
con.connect = function() {
|
||||
con.emit('connect');
|
||||
};
|
||||
con.query = function() {
|
||||
};
|
||||
client.connect();
|
||||
|
||||
var raisedDrain = false;
|
||||
client.on('drain', function() {
|
||||
raisedDrain = true;
|
||||
});
|
||||
|
||||
client.query("hello");
|
||||
client.query("sup");
|
||||
client.query('boom');
|
||||
|
||||
test("with pending queries", function() {
|
||||
test("does not emit drain", function() {
|
||||
assert.equal(raisedDrain, false);
|
||||
});
|
||||
});
|
||||
|
||||
test("after some queries executed", function() {
|
||||
con.emit('readyForQuery');
|
||||
test("does not emit drain", function() {
|
||||
assert.equal(raisedDrain, false);
|
||||
});
|
||||
});
|
||||
|
||||
test("when all queries are sent", function() {
|
||||
con.emit('readyForQuery');
|
||||
con.emit('readyForQuery');
|
||||
test("does not emit drain", function() {
|
||||
assert.equal(raisedDrain, false);
|
||||
});
|
||||
});
|
||||
|
||||
test("after last query finishes", function() {
|
||||
con.emit('readyForQuery');
|
||||
test("emits drain", function() {
|
||||
assert.ok(raisedDrain);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user