Skip to content

Commit

Permalink
test: refactor test-http-exit-delay
Browse files Browse the repository at this point in the history
test-http-exit-delay was introduced to confirm the removal of a 1 second
delay that can occur when exiting node after an http request.

This change refactors the test for simplicity and also in the hopes of
either eliminating flakiness on CI or, if not that, at least making
the source of the flakiness easier to track down.

Ref: nodejs@16b59cbc
Fixes: nodejs#4045
PR-URL: nodejs#4055
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott authored and Michael Scovetta committed Apr 2, 2016
1 parent fd3f8c6 commit 17b72c9
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions test/parallel/test-http-exit-delay.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
'use strict';
var assert = require('assert');
var common = require('../common');
var http = require('http');
const assert = require('assert');
const common = require('../common');
const http = require('http');

var start;
var server = http.createServer(function(req, res) {
const server = http.createServer(common.mustCall(function(req, res) {
req.resume();
req.on('end', function() {
res.end('Success');
});

server.close();
});

server.listen(common.PORT, 'localhost', function() {
var interval_id = setInterval(function() {
start = new Date();
if (start.getMilliseconds() > 100)
return;

console.log(start.toISOString());
var req = http.request({
'host': 'localhost',
'port': common.PORT,
'agent': false,
'method': 'PUT'
});
}));

req.end('Test');
clearInterval(interval_id);
}, 10);
});
server.listen(common.PORT, 'localhost', common.mustCall(function() {
start = new Date();
const req = http.request({
'host': 'localhost',
'port': common.PORT,
'agent': false,
'method': 'PUT'
});
req.end('Test');
}));

process.on('exit', function() {
var end = new Date();
console.log(end.toISOString());
assert.equal(start.getSeconds(), end.getSeconds());
assert(end.getMilliseconds() < 900);
console.log('ok');
const end = new Date();
assert(end - start < 1000, 'Entire test should take less than one second');
});

0 comments on commit 17b72c9

Please sign in to comment.