Skip to content

Commit

Permalink
test: revert changes to test/parallel/test-cluster-dgram-1.js
Browse files Browse the repository at this point in the history
We've started to see frequent failures in
test/parallel/test-cluster-dgram-1.js on AIX since the refactoring
in nodejs#8261.  Revert changes
until we have time to investigate properly.
  • Loading branch information
mhdawson committed Sep 2, 2016
1 parent a133b77 commit d55b825
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions test/parallel/test-cluster-dgram-1.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
const common = require('../common');
const NUM_WORKERS = 4;
const PACKETS_PER_WORKER = 10;
var NUM_WORKERS = 4;
var PACKETS_PER_WORKER = 10;

const assert = require('assert');
const cluster = require('cluster');
const dgram = require('dgram');
var assert = require('assert');
var cluster = require('cluster');
var dgram = require('dgram');


if (common.isWindows) {
Expand All @@ -28,13 +28,13 @@ function master() {
cluster.fork();

// Wait until all workers are listening.
cluster.on('listening', common.mustCall(() => {
cluster.on('listening', function() {
if (++listening < NUM_WORKERS)
return;

// Start sending messages.
const buf = Buffer.from('hello world');
const socket = dgram.createSocket('udp4');
var buf = Buffer.from('hello world');
var socket = dgram.createSocket('udp4');
var sent = 0;
doSend();

Expand All @@ -47,28 +47,31 @@ function master() {
if (sent < NUM_WORKERS * PACKETS_PER_WORKER) {
doSend();
} else {
console.log('master sent %d packets', sent);
socket.close();
}
}
}, NUM_WORKERS));
});

// Set up event handlers for every worker. Each worker sends a message when
// it has received the expected number of packets. After that it disconnects.
for (const key in cluster.workers) {
for (var key in cluster.workers) {
if (cluster.workers.hasOwnProperty(key))
setupWorker(cluster.workers[key]);
}

function setupWorker(worker) {
var received = 0;

worker.on('message', common.mustCall((msg) => {
worker.on('message', function(msg) {
received = msg.received;
}));
console.log('worker %d received %d packets', worker.id, received);
});

worker.on('disconnect', common.mustCall(() => {
assert.strictEqual(received, PACKETS_PER_WORKER);
}));
worker.on('disconnect', function() {
assert(received === PACKETS_PER_WORKER);
console.log('worker %d disconnected', worker.id);
});
}
}

Expand All @@ -79,15 +82,15 @@ function worker() {
// Create udp socket and start listening.
var socket = dgram.createSocket('udp4');

socket.on('message', common.mustCall((data, info) => {
socket.on('message', function(data, info) {
received++;

// Every 10 messages, notify the master.
if (received === PACKETS_PER_WORKER) {
if (received == PACKETS_PER_WORKER) {
process.send({received: received});
process.disconnect();
}
}, PACKETS_PER_WORKER));
});

socket.bind(common.PORT);
}

0 comments on commit d55b825

Please sign in to comment.