2010-10-30 08:48:31 +08:00
|
|
|
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() {
|
2010-11-22 13:30:10 +08:00
|
|
|
process.nextTick(function() {
|
|
|
|
assert.ok(raisedDrain);
|
|
|
|
})
|
2010-10-30 08:48:31 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|