2011-02-24 13:11:13 +08:00
|
|
|
var helper = require(__dirname + "/../test-helper");
|
2011-08-12 09:59:56 +08:00
|
|
|
var Client = require(__dirname + "/../../lib/native");
|
2011-02-24 13:11:13 +08:00
|
|
|
|
|
|
|
test('many rows', function() {
|
2011-11-22 11:42:43 +08:00
|
|
|
var client = new Client(helper.config);
|
2011-02-24 13:11:13 +08:00
|
|
|
client.connect();
|
|
|
|
var q = client.query("SELECT * FROM person");
|
|
|
|
var rows = [];
|
|
|
|
q.on('row', function(row) {
|
|
|
|
rows.push(row)
|
|
|
|
});
|
|
|
|
assert.emits(q, 'end', function() {
|
|
|
|
client.end();
|
2011-10-11 09:37:08 +08:00
|
|
|
assert.lengthIs(rows, 26);
|
2011-02-24 13:11:13 +08:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
test('many queries', function() {
|
2011-11-22 11:42:43 +08:00
|
|
|
var client = new Client(helper.config);
|
2011-02-24 13:11:13 +08:00
|
|
|
client.connect();
|
|
|
|
var count = 0;
|
|
|
|
var expected = 100;
|
|
|
|
for(var i = 0; i < expected; i++) {
|
|
|
|
var q = client.query("SELECT * FROM person");
|
|
|
|
assert.emits(q, 'end', function() {
|
|
|
|
count++;
|
2014-09-14 10:37:30 +08:00
|
|
|
});
|
2011-02-24 13:11:13 +08:00
|
|
|
}
|
|
|
|
assert.emits(client, 'drain', function() {
|
|
|
|
client.end();
|
|
|
|
assert.equal(count, expected);
|
2014-09-14 10:37:30 +08:00
|
|
|
});
|
|
|
|
});
|
2011-02-24 13:11:13 +08:00
|
|
|
|
|
|
|
test('many clients', function() {
|
|
|
|
var clients = [];
|
2011-02-25 11:19:48 +08:00
|
|
|
for(var i = 0; i < 10; i++) {
|
2011-11-22 11:42:43 +08:00
|
|
|
clients.push(new Client(helper.config));
|
2011-02-24 13:11:13 +08:00
|
|
|
}
|
|
|
|
clients.forEach(function(client) {
|
|
|
|
client.connect();
|
|
|
|
for(var i = 0; i < 20; i++) {
|
|
|
|
client.query('SELECT * FROM person');
|
|
|
|
}
|
|
|
|
assert.emits(client, 'drain', function() {
|
|
|
|
client.end();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|