-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
71 lines (61 loc) · 1.67 KB
/
test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var RSMQWorker = require( "./" );
var RedisSMQ = require("rsmq");
var WORKERCOUNT = 12;
var rsmq = new RedisSMQ( {host: "127.0.0.1", port: 6379, ns: "rsmq"} );
rsmq.setMaxListeners(WORKERCOUNT)
// count the event listener per event
var countListener = function(){
var _ret = {};
for (var evnt in rsmq._events) {
_ret[evnt] = rsmq._events[ evnt ].length;
}
return _ret
}
var workers=[];
console.log("Pre:", countListener() );
// wait a secont for rsmq connect
setTimeout( function(){
console.log("Start:", countListener() );
// generate workers
for (var i=0; i<WORKERCOUNT; i++) {
var name="worker_"+i.toString();
workers.push(new RSMQWorker(name,{
rsmq: rsmq,
autostart: true,
}))
}
setTimeout( function(){
console.log("Started all:", countListener() );
}, 1000 )
// stop some workers and check the event listeners
setTimeout( function(){
console.log("Stop ...");
for (var j=0; j<WORKERCOUNT; j += 2) {
workers[ j ].stop()
}
console.log("Stopped some", countListener() );
}, 2000 );
// restart the stopped workers
setTimeout( function(){
console.log("ReStart");
for (var j=0; j<WORKERCOUNT; j += 2) {
workers[ j ].start()
}
console.log("Restarted stopped:", countListener() );
}, 3000 );
// add more workers
setTimeout( function(){
console.log("Start more ... ");
rsmq.setMaxListeners(WORKERCOUNT*2)
for (var i=0; i<WORKERCOUNT; i++) {
var name="worker_"+i.toString();
workers.push(new RSMQWorker(name,{
rsmq: rsmq,
autostart: true,
}))
}
setTimeout( function(){
console.log("Started more workers:", countListener() );
}, 1000 )
}, 4000 );
}, 1000 );