Skip to content

Commit 6e289ea

Browse files
committed
tests: test round robin cluster order for overflow
1 parent 79b816b commit 6e289ea

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1+
var after = require('after');
12
var assert = require('assert');
23
var common = require('../../common');
34
var cluster = common.createPoolCluster();
45
var server = common.createFakeServer();
56

6-
var connCount = 0;
7+
var count = 5;
8+
var order = [];
79
var poolConfig = common.getTestConfig({port: common.fakeServerPort});
810
cluster.add('SLAVE1', poolConfig);
911
cluster.add('SLAVE2', poolConfig);
1012

13+
var done = after(count, function () {
14+
assert.deepEqual(order, [
15+
'SLAVE1',
16+
'SLAVE2',
17+
'SLAVE1',
18+
'SLAVE2',
19+
'SLAVE1'
20+
]);
21+
cluster.end(function (err) {
22+
assert.ifError(err);
23+
server.destroy();
24+
});
25+
});
26+
1127
server.listen(common.fakeServerPort, function(err) {
1228
assert.ifError(err);
1329

1430
var pool = cluster.of('SLAVE*', 'RR');
1531

16-
pool.getConnection(function (err, conn1) {
17-
assert.ifError(err);
18-
assert.strictEqual(conn1._clusterId, 'SLAVE1');
19-
20-
pool.getConnection(function (err, conn2) {
32+
for (var i = 0; i < count; i++) {
33+
pool.getConnection(function (err, conn) {
2134
assert.ifError(err);
22-
assert.strictEqual(conn2._clusterId, 'SLAVE2');
23-
24-
conn1.release();
25-
conn2.release();
26-
27-
cluster.end(function (err) {
28-
assert.ifError(err);
29-
server.destroy();
30-
});
35+
order.push(conn._clusterId);
36+
conn.release();
37+
done();
3138
});
32-
});
39+
}
3340
});

0 commit comments

Comments
 (0)