Skip to content

Commit 70f8b99

Browse files
committed
added sink object for testing async long running query pool
1 parent 0d7936f commit 70f8b99

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

test/test-helper.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ assert.length = function(actual, expectedLength) {
8585
var expect = function(callback, timeout) {
8686
var executed = false;
8787
var id = setTimeout(function() {
88-
assert.ok(executed, "Expected execution of " + callback + " fired");
88+
assert.ok(executed, "Expected execution of funtion to be fired");
8989
}, timeout || 2000)
9090

9191
return function(err, queryResult) {
@@ -140,7 +140,42 @@ process.on('exit', function() {
140140
throw error.e;
141141
});
142142
});
143+
var count = 0;
144+
145+
var Sink = function(expected, timeout, callback) {
146+
var defaultTimeout = 1000;
147+
if(typeof timeout == 'function') {
148+
callback = timeout;
149+
timeout = defaultTimeout;
150+
}
151+
timeout = timeout || defaultTimeout;
152+
var internalCount = 0;
153+
var kill = function() {
154+
assert.ok(false, "Did not reach expected " + expected + " with an idle timeout of " + timeout);
155+
}
156+
var killTimeout = setTimeout(kill, timeout);
157+
return {
158+
add: function(count) {
159+
count = count || 1;
160+
internalCount += count;
161+
clearTimeout(killTimeout)
162+
if(internalCount < expected) {
163+
killTimeout = setTimeout(kill, timeout)
164+
}
165+
else {
166+
assert.equal(internalCount, expected);
167+
callback();
168+
}
169+
}
170+
}
171+
}
143172

144173
module.exports = {
145-
args: args
174+
args: args,
175+
Sink: Sink,
176+
connectionString: function() {
177+
return "pg"+(count++)+"://"+args.user+":"+args.password+"@"+args.host+":"+args.port+"/"+args.database;
178+
}
146179
};
180+
181+

0 commit comments

Comments
 (0)