You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

50 lines
1.0 KiB

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const server = http.createServer(common.mustCall((req, res) => {
if (req.url === '/first') {
res.end('ok');
return;
}
setTimeout(() => {
res.end('ok');
}, common.platformTimeout(500));
}, 2));
server.keepAliveTimeout = common.platformTimeout(200);
const agent = new http.Agent({
keepAlive: true,
maxSockets: 1
});
function request(path, callback) {
const port = server.address().port;
const req = http.request({ agent, path, port }, common.mustCall((res) => {
assert.strictEqual(res.statusCode, 200);
res.setEncoding('utf8');
let result = '';
res.on('data', (chunk) => {
result += chunk;
});
res.on('end', common.mustCall(() => {
assert.strictEqual(result, 'ok');
callback();
}));
}));
req.end();
}
server.listen(0, common.mustCall(() => {
request('/first', () => {
request('/second', () => {
server.close();
});
});
}));