0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http-client-pipe-end.js
Rich Trott a1040f2065 test: refresh temp directory when using pipe
common.PIPE resides in the temp directory (except on Windows). Insure
that the temp directory is refreshed in tests that use common.PIPE.

PR-URL: https://github.com/nodejs/node/pull/3231
Fixes: https://github.com/nodejs/node/issues/3227
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-10-08 20:05:22 -07:00

42 lines
780 B
JavaScript

'use strict';
// see https://github.com/joyent/node/issues/3257
var common = require('../common');
var assert = require('assert');
var http = require('http');
var server = http.createServer(function(req, res) {
req.resume();
req.once('end', function() {
res.writeHead(200);
res.end();
server.close();
});
});
common.refreshTmpDir();
server.listen(common.PIPE, function() {
var req = http.request({
socketPath: common.PIPE,
headers: {'Content-Length':'1'},
method: 'POST',
path: '/'
});
req.write('.');
sched(function() { req.end(); }, 5);
});
// schedule a callback after `ticks` event loop ticks
function sched(cb, ticks) {
function fn() {
if (--ticks)
setImmediate(fn);
else
cb();
}
setImmediate(fn);
}