Skip to content

Commit c98ebb5

Browse files
author
Christophe Macabiau
committed
query cancellation test
1 parent f3c8b97 commit c98ebb5

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var helper = require(__dirname+"/test-helper");
2+
var pg = require(__dirname + '/../../../lib');
3+
4+
//before running this test make sure you run the script create-test-tables
5+
test("cancellation of a query", function() {
6+
7+
var client = helper.client();
8+
9+
var qry = client.query("select name from person order by name");
10+
11+
client.on('drain', client.end.bind(client));
12+
13+
var rows1 = 0, rows2 = 0, rows3 = 0, rows4 = 0;
14+
15+
var query1 = client.query(qry);
16+
query1.on('row', function(row) {
17+
rows1++;
18+
});
19+
var query2 = client.query(qry);
20+
query2.on('row', function(row) {
21+
rows2++;
22+
});
23+
var query3 = client.query(qry);
24+
query3.on('row', function(row) {
25+
rows3++;
26+
});
27+
var query4 = client.query(qry);
28+
query4.on('row', function(row) {
29+
rows4++;
30+
});
31+
32+
pg.cancel(helper.connectionString, client, query1);
33+
pg.cancel(helper.connectionString, client, query2);
34+
pg.cancel(helper.connectionString, client, query4);
35+
36+
setTimeout(function() {
37+
assert.equal(rows1, 0);
38+
assert.equal(rows2, 0);
39+
assert.equal(rows4, 0);
40+
}, 2000);
41+
42+
assert.emits(query3, 'end', function() {
43+
test("returned right number of rows", function() {
44+
assert.equal(rows3, 26);
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)