Skip to content

Commit 627b38b

Browse files
committed
tests: add pool cluster random test
1 parent 6e289ea commit 627b38b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"istanbul": "0.4.5",
2323
"require-all": "2.1.0",
2424
"rimraf": "2.2.8",
25+
"seedrandom": "2.4.2",
2526
"timezone-mock": "0.0.0",
2627
"mkdirp": "0.5.1",
2728
"urun": "0.0.8",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var seedrandom = require('seedrandom');
4+
var cluster = common.createPoolCluster();
5+
var server = common.createFakeServer();
6+
7+
var poolConfig = common.getTestConfig({port: common.fakeServerPort});
8+
cluster.add('SLAVE1', poolConfig);
9+
cluster.add('SLAVE2', poolConfig);
10+
cluster.add('SLAVE3', poolConfig);
11+
12+
server.listen(common.fakeServerPort, function(err) {
13+
assert.ifError(err);
14+
15+
var count = 7;
16+
var order = [];
17+
var pool = cluster.of('SLAVE*', 'RANDOM');
18+
19+
seedrandom('cluster random rest', {
20+
global: true
21+
});
22+
23+
next();
24+
25+
function done() {
26+
assert.deepEqual(order, [
27+
'SLAVE2',
28+
'SLAVE3',
29+
'SLAVE2',
30+
'SLAVE2',
31+
'SLAVE1',
32+
'SLAVE2',
33+
'SLAVE1'
34+
]);
35+
cluster.end(function (err) {
36+
assert.ifError(err);
37+
server.destroy();
38+
});
39+
}
40+
41+
function next() {
42+
pool.getConnection(function (err, conn) {
43+
assert.ifError(err);
44+
order.push(conn._clusterId);
45+
conn.release();
46+
47+
if (--count > 0) {
48+
next();
49+
} else {
50+
done();
51+
}
52+
});
53+
}
54+
});

0 commit comments

Comments
 (0)