Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-pipe-file-to-http #10054

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions test/parallel/test-pipe-file-to-http.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
var http = require('http');
var path = require('path');
var cp = require('child_process');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const http = require('http');
const path = require('path');
const cp = require('child_process');

common.refreshTmpDir();

var filename = path.join(common.tmpDir || '/tmp', 'big');
var clientReqComplete = false;
var count = 0;
const filename = path.join(common.tmpDir || '/tmp', 'big');
let count = 0;

var server = http.createServer(function(req, res) {
var timeoutId;
assert.equal('POST', req.method);
const server = http.createServer(function(req, res) {
let timeoutId;
assert.strictEqual('POST', req.method);
req.pause();

setTimeout(function() {
Expand All @@ -36,27 +35,26 @@ var server = http.createServer(function(req, res) {
server.listen(0);

server.on('listening', function() {
var cmd = common.ddCommand(filename, 10240);
const cmd = common.ddCommand(filename, 10240);

cp.exec(cmd, function(err, stdout, stderr) {
cp.exec(cmd, function(err) {
if (err) throw err;
makeRequest();
});
});

function makeRequest() {
var req = http.request({
const req = http.request({
port: server.address().port,
path: '/',
method: 'POST'
});

var s = fs.ReadStream(filename);
const s = fs.ReadStream(filename);
s.pipe(req);
s.on('close', function(err) {
if (err) throw err;
clientReqComplete = true;
});
s.on('close', common.mustCall((err) => {
assert.ifError(err);
}));

req.on('response', function(res) {
res.resume();
Expand All @@ -67,6 +65,5 @@ function makeRequest() {
}

process.on('exit', function() {
assert.equal(1024 * 10240, count);
assert.ok(clientReqComplete);
assert.strictEqual(1024 * 10240, count);
});