forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery-queue-tests.js
More file actions
112 lines (95 loc) · 2.61 KB
/
query-queue-tests.js
File metadata and controls
112 lines (95 loc) · 2.61 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var helper = require(__dirname + '/test-helper');
var Connection = require(__dirname + '/../../../lib/connection');
test('drain', function() {
var con = new Connection({stream: "NO"});
var client = new Client({connection:con});
con.connect = function() {
con.emit('connect');
};
con.query = function() {
};
client.connect();
var raisedDrain = false;
client.on('drain', function() {
raisedDrain = true;
});
client.query("hello");
client.query("sup");
client.query('boom');
test("with pending queries", function() {
test("does not emit drain", function() {
assert.equal(raisedDrain, false);
});
});
test("after some queries executed", function() {
con.emit('readyForQuery');
test("does not emit drain", function() {
assert.equal(raisedDrain, false);
});
});
test("when all queries are sent", function() {
con.emit('readyForQuery');
con.emit('readyForQuery');
test("does not emit drain", function() {
assert.equal(raisedDrain, false);
});
});
test("after last query finishes", function() {
con.emit('readyForQuery');
test("emits drain", function() {
process.nextTick(function() {
assert.ok(raisedDrain);
})
});
});
});
test('with drain paused', function() {
//mock out a fake connection
var con = new Connection({stream: "NO"});
con.connect = function() {
con.emit('connect');
};
con.query = function() {
};
var client = new Client({connection:con});
client.connect();
var drainCount = 0;
client.on('drain', function() {
drainCount++;
});
test('normally unpaused', function() {
con.emit('readyForQuery');
client.query('boom');
assert.emits(client, 'drain', function() {
assert.equal(drainCount, 1);
});
con.emit('readyForQuery');
});
test('pausing', function() {
test('unpaused with no queries in between', function() {
client.pauseDrain();
client.resumeDrain();
assert.equal(drainCount, 1);
});
test('paused', function() {
test('resumeDrain after empty', function() {
client.pauseDrain();
client.query('asdf');
con.emit('readyForQuery');
assert.equal(drainCount, 1);
client.resumeDrain();
assert.equal(drainCount, 2);
});
test('resumDrain while still pending', function() {
client.pauseDrain();
client.query('asdf');
client.query('asdf1');
con.emit('readyForQuery');
client.resumeDrain();
assert.equal(drainCount, 2);
con.emit('readyForQuery');
assert.equal(drainCount, 3);
});
});
});
});