|
1 | 1 | 'use strict'; |
2 | | -var common = require('../common'); |
3 | | -var assert = require('assert'); |
4 | | -var net = require('net'); |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const net = require('net'); |
5 | 5 |
|
6 | | -var buf = new Buffer(10 * 1024 * 1024); |
| 6 | +const buf = new Buffer(10 * 1024 * 1024); |
7 | 7 |
|
8 | 8 | buf.fill(0x62); |
9 | 9 |
|
10 | 10 | var errs = []; |
11 | 11 |
|
12 | | -var srv = net.createServer(function onConnection(conn) { |
13 | | - conn.write(buf); |
| 12 | +const srv = net.createServer(function onConnection(conn) { |
| 13 | + setImmediate(() => { |
| 14 | + conn.write(buf); |
| 15 | + }); |
| 16 | + |
14 | 17 | conn.on('error', function(err) { |
15 | 18 | errs.push(err); |
16 | | - if (errs.length > 1 && errs[0] === errs[1]) |
17 | | - assert(false, 'We should not be emitting the same error twice'); |
| 19 | + if (errs.length > 1) |
| 20 | + assert(errs[0] !== errs[1], 'Should not get the same error twice'); |
18 | 21 | }); |
19 | 22 | conn.on('close', function() { |
20 | 23 | srv.unref(); |
21 | 24 | }); |
22 | 25 | }).listen(common.PORT, function() { |
23 | | - var client = net.connect({ port: common.PORT }); |
24 | | - |
25 | | - client.on('connect', function() { |
26 | | - client.destroy(); |
27 | | - }); |
| 26 | + const client = net.connect({ port: common.PORT }); |
| 27 | + client.on('connect', client.destroy); |
28 | 28 | }); |
29 | 29 |
|
30 | 30 | process.on('exit', function() { |
31 | | - console.log(errs); |
32 | 31 | assert.equal(errs.length, 1); |
33 | 32 | }); |
0 commit comments