-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest-connection-cycling-lifo.js
48 lines (42 loc) · 1.3 KB
/
test-connection-cycling-lifo.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
var after = require('after');
var assert = require('assert');
var common = require('../../common');
var pool = common.createPool({
port : common.fakeServerPort,
roundRobinConnectionCycling : false
});
var server = common.createFakeServer();
var lastConnectionId = null;
var numberOfConnections = 4;
server.listen(common.fakeServerPort, function (err) {
assert.ifError(err);
var getConnectionAndEnsureItsTheLastConnection = function(cb) {
pool.getConnection(function (err, connection) {
assert.ifError(err);
assert.ok(connection.id === lastConnectionId);
connection.release();
if (cb) cb();
});
};
var done = after(numberOfConnections, function () {
getConnectionAndEnsureItsTheLastConnection(function() {
getConnectionAndEnsureItsTheLastConnection(function() {
pool.end(function (err) {
assert.ifError(err);
server.destroy();
});
});
});
});
var counter = 1;
var createIndexedConnection = function () {
pool.getConnection(function (err, connection) {
assert.ifError(err);
connection.id = counter++;
lastConnectionId = connection.id;
connection.release();
done();
});
};
Array.apply(null, Array(numberOfConnections)).map(createIndexedConnection);
});