forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress-tests.js
49 lines (46 loc) · 1.15 KB
/
stress-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var helper = require(__dirname + "/../test-helper");
var Client = require(__dirname + "/../../lib/native");
test('many rows', function() {
var client = new Client(helper.config);
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();
assert.lengthIs(rows, 26);
})
});
test('many queries', function() {
var client = new Client(helper.config);
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++;
});
}
assert.emits(client, 'drain', function() {
client.end();
assert.equal(count, expected);
});
});
test('many clients', function() {
var clients = [];
for(var i = 0; i < 10; i++) {
clients.push(new Client(helper.config));
}
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();
})
})
})