mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 20:09:32 +00:00

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>
40 lines
762 B
JavaScript
40 lines
762 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var http = require('http');
|
|
|
|
var expected = 'Post Body For Test';
|
|
var result = '';
|
|
|
|
var server = http.Server(function(req, res) {
|
|
req.setEncoding('utf8');
|
|
req.on('data', function(chunk) {
|
|
result += chunk;
|
|
});
|
|
|
|
req.on('end', function() {
|
|
server.close();
|
|
res.writeHead(200);
|
|
res.end('hello world\n');
|
|
});
|
|
|
|
});
|
|
|
|
server.listen(0, function() {
|
|
http.request({
|
|
port: this.address().port,
|
|
path: '/',
|
|
method: 'POST'
|
|
}, function(res) {
|
|
console.log(res.statusCode);
|
|
res.resume();
|
|
}).on('error', function(e) {
|
|
console.log(e.message);
|
|
process.exit(1);
|
|
}).end(expected);
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(expected, result);
|
|
});
|