mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
2bc7841d0f
This helps to prevent issues where a failed test can keep a bound socket open long enough to cause other tests to fail with EADDRINUSE because the same port number is used. PR-URL: https://github.com/nodejs/node/pull/7045 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
// Spec documentation http://httpwg.github.io/specs/rfc7231.html#header.expect
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
const tests = [417, 417];
|
|
|
|
let testsComplete = 0;
|
|
let testIdx = 0;
|
|
|
|
const s = http.createServer(function(req, res) {
|
|
throw new Error('this should never be executed');
|
|
});
|
|
|
|
s.listen(0, nextTest);
|
|
|
|
function nextTest() {
|
|
const options = {
|
|
port: s.address().port,
|
|
headers: { 'Expect': 'meoww' }
|
|
};
|
|
|
|
if (testIdx === tests.length) {
|
|
return s.close();
|
|
}
|
|
|
|
const test = tests[testIdx];
|
|
|
|
if (testIdx > 0) {
|
|
s.on('checkExpectation', common.mustCall((req, res) => {
|
|
res.statusCode = 417;
|
|
res.end();
|
|
}));
|
|
}
|
|
|
|
http.get(options, function(response) {
|
|
console.log('client: expected status: ' + test);
|
|
console.log('client: statusCode: ' + response.statusCode);
|
|
assert.equal(response.statusCode, test);
|
|
assert.equal(response.statusMessage, 'Expectation Failed');
|
|
|
|
response.on('end', function() {
|
|
testsComplete++;
|
|
testIdx++;
|
|
nextTest();
|
|
});
|
|
response.resume();
|
|
});
|
|
}
|
|
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(2, testsComplete);
|
|
});
|