Skip to content

Commit

Permalink
test: fix flaky http-chunked-304 on smartos
Browse files Browse the repository at this point in the history
SmartOS has an issue where it will trigger ECONNREFUSED when it
should not. See https://smartos.org/bugview/OS-2767.

This change adds logic to test-http-chunked-304 to work around
the issue. See also similar issue: nodejs#2663

Fixes: nodejs#3864
  • Loading branch information
fansworld-claudio committed Nov 19, 2015
1 parent e4e5b13 commit 89d67c3
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions test/parallel/test-http-chunked-304.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,38 @@ function test(statusCode, next) {
});

server.listen(common.PORT, function() {
var conn = net.createConnection(common.PORT, function() {
conn.write('GET / HTTP/1.1\r\n\r\n');
var conn = net.createConnection(common.PORT);
var gotSunOSError = false;
var resp = '';

var resp = '';
conn.on('connect', function() {
resp = '';
conn.setEncoding('utf8');
conn.on('data', function(data) {
resp += data;
});
gotSunOSError = false;

conn.on('end', common.mustCall(function() {
conn.write('GET / HTTP/1.1\r\n\r\n');
});

conn.on('data', function(data) {
resp += data;
});

conn.on('error', function(e) {
// Retry if SmartOS and ECONNREFUSED. See
// https://github.com/nodejs/node/issues/2663.
if (common.isSunOS && (e.code === 'ECONNREFUSED')) {
gotSunOSError = true;
conn.connect(common.PORT);
}
console.error('error: %s', e);
});

conn.on('end', common.mustCall(function() {
if (!common.isSunOS || !gotSunOSError) {
assert.equal(/^Connection: close\r\n$/m.test(resp), true);
assert.equal(/^0\r\n$/m.test(resp), false);
if (next) process.nextTick(next);
}));
});
}
}));
});
}

0 comments on commit 89d67c3

Please sign in to comment.