|
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 | + process.nextTick(() => { conn.write(buf); }); |
14 | 14 | conn.on('error', function(err) {
|
15 | 15 | errs.push(err);
|
16 |
| - if (errs.length > 1 && errs[0] === errs[1]) |
17 |
| - assert(false, 'We should not be emitting the same error twice'); |
| 16 | + if (errs.length > 1) |
| 17 | + assert(errs[0] !== errs[1], 'Should not get the same error twice'); |
18 | 18 | });
|
19 | 19 | conn.on('close', function() {
|
20 | 20 | srv.unref();
|
21 | 21 | });
|
22 | 22 | }).listen(common.PORT, function() {
|
23 |
| - var client = net.connect({ port: common.PORT }); |
24 |
| - |
25 |
| - client.on('connect', function() { |
26 |
| - client.destroy(); |
27 |
| - }); |
| 23 | + const client = net.connect({ port: common.PORT }); |
| 24 | + client.on('connect', client.destroy); |
28 | 25 | });
|
29 | 26 |
|
30 | 27 | process.on('exit', function() {
|
31 |
| - console.log(errs); |
32 | 28 | assert.equal(errs.length, 1);
|
33 | 29 | });
|
0 commit comments