Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor flaky net-error-twice #4061

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions test/parallel/test-net-error-twice.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var net = require('net');
const common = require('../common');
const assert = require('assert');
const net = require('net');

var buf = new Buffer(10 * 1024 * 1024);
const buf = new Buffer(10 * 1024 * 1024);

buf.fill(0x62);

var errs = [];

var srv = net.createServer(function onConnection(conn) {
conn.write(buf);
const srv = net.createServer(function onConnection(conn) {
process.nextTick(() => { conn.write(buf); });
conn.on('error', function(err) {
errs.push(err);
if (errs.length > 1 && errs[0] === errs[1])
assert(false, 'We should not be emitting the same error twice');
if (errs.length > 1)
assert(errs[0] !== errs[1], 'Should not get the same error twice');
});
conn.on('close', function() {
srv.unref();
});
}).listen(common.PORT, function() {
var client = net.connect({ port: common.PORT });

client.on('connect', function() {
client.destroy();
});
const client = net.connect({ port: common.PORT });
client.on('connect', client.destroy);
});

process.on('exit', function() {
console.log(errs);
assert.equal(errs.length, 1);
});