|
1 | 1 | 'use strict'; |
2 | | -require('../common'); |
| 2 | +const common = require('../common'); |
3 | 3 | const cluster = require('cluster'); |
4 | 4 | const assert = require('assert'); |
5 | 5 |
|
6 | 6 | if (cluster.isMaster) { |
7 | 7 | const worker = cluster.fork(); |
8 | 8 |
|
9 | | - assert.ok(worker.isConnected(), |
10 | | - 'isConnected() should return true as soon as the worker has ' + |
11 | | - 'been created.'); |
| 9 | + assert.strictEqual(worker.isConnected(), true); |
12 | 10 |
|
13 | | - worker.on('disconnect', function() { |
14 | | - assert.ok(!worker.isConnected(), |
15 | | - 'After a disconnect event has been emitted, ' + |
16 | | - 'isConncted should return false'); |
17 | | - }); |
| 11 | + worker.on('disconnect', common.mustCall(() => { |
| 12 | + assert.strictEqual(worker.isConnected(), false); |
| 13 | + })); |
18 | 14 |
|
19 | 15 | worker.on('message', function(msg) { |
20 | 16 | if (msg === 'readyToDisconnect') { |
21 | 17 | worker.disconnect(); |
22 | 18 | } |
23 | 19 | }); |
24 | | - |
25 | 20 | } else { |
26 | | - assert.ok(cluster.worker.isConnected(), |
27 | | - 'isConnected() should return true from within a worker at all ' + |
28 | | - 'times.'); |
| 21 | + function assertNotConnected() { |
| 22 | + assert.strictEqual(cluster.worker.isConnected(), false); |
| 23 | + } |
29 | 24 |
|
30 | | - cluster.worker.process.on('disconnect', function() { |
31 | | - assert.ok(!cluster.worker.isConnected(), |
32 | | - 'isConnected() should return false from within a worker ' + |
33 | | - 'after its underlying process has been disconnected from ' + |
34 | | - 'the master'); |
35 | | - }); |
| 25 | + assert.strictEqual(cluster.worker.isConnected(), true); |
| 26 | + cluster.worker.on('disconnect', common.mustCall(assertNotConnected)); |
| 27 | + cluster.worker.process.on('disconnect', common.mustCall(assertNotConnected)); |
36 | 28 |
|
37 | 29 | process.send('readyToDisconnect'); |
38 | 30 | } |
0 commit comments