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 test-http-exit-delay #4055

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
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');
});