|
2 | 2 | // Test that a Linux specific quirk in the handle passing protocol is handled
|
3 | 3 | // correctly. See https://github.com/joyent/node/issues/5330 for details.
|
4 | 4 |
|
5 |
| -var common = require('../common'); |
6 |
| -var assert = require('assert'); |
7 |
| -var net = require('net'); |
8 |
| -var spawn = require('child_process').spawn; |
| 5 | +const common = require('../common'); |
| 6 | +const assert = require('assert'); |
| 7 | +const net = require('net'); |
| 8 | +const spawn = require('child_process').spawn; |
9 | 9 |
|
10 | 10 | if (process.argv[2] === 'worker')
|
11 | 11 | worker();
|
|
15 | 15 | function master() {
|
16 | 16 | // spawn() can only create one IPC channel so we use stdin/stdout as an
|
17 | 17 | // ad-hoc command channel.
|
18 |
| - var proc = spawn(process.execPath, [__filename, 'worker'], { |
| 18 | + const proc = spawn(process.execPath, [__filename, 'worker'], { |
19 | 19 | stdio: ['pipe', 'pipe', 'pipe', 'ipc']
|
20 | 20 | });
|
21 |
| - var handle = null; |
22 |
| - proc.on('exit', function() { |
| 21 | + let handle = null; |
| 22 | + proc.on('exit', () => { |
23 | 23 | handle.close();
|
24 | 24 | });
|
25 |
| - proc.stdout.on('data', function(data) { |
26 |
| - assert.equal(data, 'ok\r\n'); |
| 25 | + proc.stdout.on('data', common.mustCall((data) => { |
| 26 | + assert.strictEqual(data.toString(), 'ok\r\n'); |
27 | 27 | net.createServer(common.fail).listen(0, function() {
|
28 | 28 | handle = this._handle;
|
29 | 29 | proc.send('one');
|
30 | 30 | proc.send('two', handle);
|
31 | 31 | proc.send('three');
|
32 | 32 | proc.stdin.write('ok\r\n');
|
33 | 33 | });
|
34 |
| - }); |
| 34 | + })); |
35 | 35 | proc.stderr.pipe(process.stderr);
|
36 | 36 | }
|
37 | 37 |
|
38 | 38 | function worker() {
|
39 | 39 | process._channel.readStop(); // Make messages batch up.
|
40 | 40 | process.stdout.ref();
|
41 | 41 | process.stdout.write('ok\r\n');
|
42 |
| - process.stdin.once('data', function(data) { |
43 |
| - assert.equal(data, 'ok\r\n'); |
| 42 | + process.stdin.once('data', common.mustCall((data) => { |
| 43 | + assert.strictEqual(data.toString(), 'ok\r\n'); |
44 | 44 | process._channel.readStart();
|
45 |
| - }); |
46 |
| - var n = 0; |
47 |
| - process.on('message', function(msg, handle) { |
| 45 | + })); |
| 46 | + let n = 0; |
| 47 | + process.on('message', common.mustCall((msg, handle) => { |
48 | 48 | n += 1;
|
49 | 49 | if (n === 1) {
|
50 |
| - assert.equal(msg, 'one'); |
51 |
| - assert.equal(handle, undefined); |
| 50 | + assert.strictEqual(msg, 'one'); |
| 51 | + assert.strictEqual(handle, undefined); |
52 | 52 | } else if (n === 2) {
|
53 |
| - assert.equal(msg, 'two'); |
54 |
| - assert.equal(typeof handle, 'object'); // Also matches null, therefore... |
55 |
| - assert.ok(handle); // also check that it's truthy. |
| 53 | + assert.strictEqual(msg, 'two'); |
| 54 | + assert.ok(handle !== null && typeof handle === 'object'); |
56 | 55 | handle.close();
|
57 | 56 | } else if (n === 3) {
|
58 |
| - assert.equal(msg, 'three'); |
59 |
| - assert.equal(handle, undefined); |
| 57 | + assert.strictEqual(msg, 'three'); |
| 58 | + assert.strictEqual(handle, undefined); |
60 | 59 | process.exit();
|
61 | 60 | }
|
62 |
| - }); |
| 61 | + }, 3)); |
63 | 62 | }
|
0 commit comments