summaryrefslogtreecommitdiff
path: root/test/parallel/test-cluster-dgram-2.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-08-24 13:55:12 -0700
committerJames M Snell <jasnell@gmail.com>2016-09-01 07:13:47 -0700
commitbaa0ffdab37a490e8ca69c82772425f8bdec0ec2 (patch)
tree778fb8017556b49c5b17fa89e72da4d5de19ced2 /test/parallel/test-cluster-dgram-2.js
parent2168432c3616a841699814786a9bc52e7f819e6b (diff)
downloadandroid-node-v8-baa0ffdab37a490e8ca69c82772425f8bdec0ec2.tar.gz
android-node-v8-baa0ffdab37a490e8ca69c82772425f8bdec0ec2.tar.bz2
android-node-v8-baa0ffdab37a490e8ca69c82772425f8bdec0ec2.zip
test: refactor/cleanup a number of cluster tests
* Move shared code into common * Favor use of strictEqual * Add some missing common.mustCalls * Other general cleanup PR-URL: https://github.com/nodejs/node/pull/8261 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Diffstat (limited to 'test/parallel/test-cluster-dgram-2.js')
-rw-r--r--test/parallel/test-cluster-dgram-2.js22
1 files changed, 9 insertions, 13 deletions
diff --git a/test/parallel/test-cluster-dgram-2.js b/test/parallel/test-cluster-dgram-2.js
index 65f46a9cd8..179b1ee153 100644
--- a/test/parallel/test-cluster-dgram-2.js
+++ b/test/parallel/test-cluster-dgram-2.js
@@ -1,10 +1,10 @@
'use strict';
const common = require('../common');
-var NUM_WORKERS = 4;
-var PACKETS_PER_WORKER = 10;
+const NUM_WORKERS = 4;
+const PACKETS_PER_WORKER = 10;
-var cluster = require('cluster');
-var dgram = require('dgram');
+const cluster = require('cluster');
+const dgram = require('dgram');
if (common.isWindows) {
@@ -28,11 +28,10 @@ function master() {
// Disconnect workers when the expected number of messages have been
// received.
- socket.on('message', function(data, info) {
+ socket.on('message', common.mustCall((data, info) => {
received++;
- if (received == PACKETS_PER_WORKER * NUM_WORKERS) {
- console.log('master received %d packets', received);
+ if (received === PACKETS_PER_WORKER * NUM_WORKERS) {
// Close the socket.
socket.close();
@@ -40,7 +39,7 @@ function master() {
// Disconnect all workers.
cluster.disconnect();
}
- });
+ }, NUM_WORKERS * PACKETS_PER_WORKER));
// Fork workers.
for (var i = 0; i < NUM_WORKERS; i++)
@@ -50,8 +49,8 @@ function master() {
function worker() {
// Create udp socket and send packets to master.
- var socket = dgram.createSocket('udp4');
- var buf = Buffer.from('hello world');
+ const socket = dgram.createSocket('udp4');
+ const buf = Buffer.from('hello world');
// This test is intended to exercise the cluster binding of udp sockets, but
// since sockets aren't clustered when implicitly bound by at first call of
@@ -60,7 +59,4 @@ function worker() {
for (var i = 0; i < PACKETS_PER_WORKER; i++)
socket.send(buf, 0, buf.length, common.PORT, '127.0.0.1');
-
- console.log('worker %d sent %d packets', cluster.worker.id,
- PACKETS_PER_WORKER);
}