Skip to content

Commit

Permalink
Fix master worker queue test
Browse files Browse the repository at this point in the history
  • Loading branch information
jfd committed Mar 6, 2011
1 parent 23471c7 commit be6c35f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
12 changes: 7 additions & 5 deletions test/messaging/master-worker-queue/test.js
Expand Up @@ -21,13 +21,15 @@ master.on("connect", function() {
if (++connections == POOL_SIZE) {
var reqcount = REQUESTS_TO_SEND;
while (reqcount--) {
master.send("do", function(msg, ok, token) {
equal(ok, 'OK');
var req = master.send("test");
req.receive = function ok(msg, token) {

if (tokens.indexOf(token) !== -1) {
throw new Error("Token already received");
}

tokens.push(token);
// console.log("count: %s, of: %s" , count, REQUESTS_TO_SEND);

if (++count == REQUESTS_TO_SEND) {
equal(master._readySockets.length, POOL_SIZE);
for (var i = 0; i < POOL_SIZE; i++) {
Expand All @@ -40,7 +42,7 @@ master.on("connect", function() {
}
master.sockets.forEach(function(sock) { sock.kill() });
}
});
};
}
}
});
Expand All @@ -50,5 +52,5 @@ master.on("disconnect", function() {
});

for (var i = 0; i < POOL_SIZE; i++) {
master.attach(spawn("./worker"));
master.attach(spawn("./worker", "pipe"));
}
13 changes: 4 additions & 9 deletions test/messaging/master-worker-queue/worker.js
@@ -1,14 +1,9 @@
const equal = require("assert").equal
, createChannel = require("../../../lib").createChannel
, send = require("../../../lib/").send
, decode = require("../../../lib/").decode
, receive = require("../../../lib/").receive
, openStdMsg = require("../../../lib/util").openStdMsg

var worker = null
, count = 0;

receive (
'do', function() {
this.send('OK', process.pid.toString() + (count++));
}
);
openStdMsg().receive = function test(msg) {
msg.send("ok", process.pid.toString() + (count++));
};

0 comments on commit be6c35f

Please sign in to comment.