2013-03-29 02:24:33 +08:00
|
|
|
var helper = require(__dirname + '/test-helper');
|
|
|
|
var Connection = require(__dirname + '/../../../lib/connection');
|
|
|
|
var Client = require(__dirname + '/../../../lib/client');
|
|
|
|
|
|
|
|
test('emits end when not in query', function() {
|
|
|
|
var stream = new (require('events').EventEmitter)();
|
|
|
|
stream.write = function() {
|
|
|
|
//NOOP
|
|
|
|
}
|
|
|
|
var client = new Client({connection: new Connection({stream: stream})});
|
|
|
|
client.connect(assert.calls(function() {
|
|
|
|
client.query('SELECT NOW()', assert.calls(function(err, result) {
|
|
|
|
assert(err);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
assert.emits(client, 'end');
|
|
|
|
client.connection.emit('connect');
|
|
|
|
process.nextTick(function() {
|
|
|
|
client.connection.emit('readyForQuery');
|
|
|
|
assert.equal(client.queryQueue.length, 0);
|
|
|
|
assert(client.activeQuery, 'client should have issued query');
|
|
|
|
process.nextTick(function() {
|
2014-04-04 22:11:44 +08:00
|
|
|
stream.emit('close');
|
2013-03-29 02:24:33 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|