2011-11-02 23:35:09 +08:00
|
|
|
var helper = require(__dirname+"/test-helper");
|
|
|
|
|
|
|
|
//before running this test make sure you run the script create-test-tables
|
|
|
|
test("cancellation of a query", function() {
|
|
|
|
|
|
|
|
var client = helper.client();
|
|
|
|
|
2012-12-11 12:44:58 +08:00
|
|
|
var qry = "select name from person order by name";
|
2011-11-02 23:35:09 +08:00
|
|
|
|
|
|
|
client.on('drain', client.end.bind(client));
|
|
|
|
|
2014-10-10 09:12:17 +08:00
|
|
|
var rows3 = 0;
|
2012-12-11 12:44:58 +08:00
|
|
|
|
|
|
|
var query1 = client.query(qry);
|
|
|
|
query1.on('row', function(row) {
|
2014-10-10 09:12:17 +08:00
|
|
|
throw new Error('Should not emit a row')
|
2012-12-11 12:44:58 +08:00
|
|
|
});
|
|
|
|
var query2 = client.query(qry);
|
|
|
|
query2.on('row', function(row) {
|
2014-10-10 09:12:17 +08:00
|
|
|
throw new Error('Should not emit a row')
|
2012-12-11 12:44:58 +08:00
|
|
|
});
|
|
|
|
var query3 = client.query(qry);
|
|
|
|
query3.on('row', function(row) {
|
|
|
|
rows3++;
|
|
|
|
});
|
|
|
|
var query4 = client.query(qry);
|
|
|
|
query4.on('row', function(row) {
|
2014-10-10 09:12:17 +08:00
|
|
|
throw new Error('Should not emit a row')
|
2012-12-11 12:44:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
helper.pg.cancel(helper.config, client, query1);
|
|
|
|
helper.pg.cancel(helper.config, client, query2);
|
|
|
|
helper.pg.cancel(helper.config, client, query4);
|
|
|
|
|
2011-11-02 23:35:09 +08:00
|
|
|
assert.emits(query3, 'end', function() {
|
2012-12-11 12:44:58 +08:00
|
|
|
test("returned right number of rows", function() {
|
|
|
|
assert.equal(rows3, 26);
|
|
|
|
});
|
|
|
|
});
|
2011-11-02 23:35:09 +08:00
|
|
|
});
|