mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +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>
31 lines
617 B
JavaScript
31 lines
617 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var http = require('http');
|
|
var net = require('net');
|
|
|
|
var received = '';
|
|
|
|
var server = http.createServer(function(req, res) {
|
|
res.writeHead(200);
|
|
res.end();
|
|
|
|
req.socket.on('data', function(data) {
|
|
received += data;
|
|
});
|
|
|
|
server.close();
|
|
}).listen(0, function() {
|
|
var socket = net.connect(this.address().port, function() {
|
|
socket.write('PUT / HTTP/1.1\r\n\r\n');
|
|
|
|
socket.once('data', function() {
|
|
socket.end('hello world');
|
|
});
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(received, 'hello world');
|
|
});
|