test: refactor test-pipe-file-to-http
Changing var defs to const/let, changing assert.equal to assert.strictEqual. Wrapping functions called once with common.mustCall PR-URL: https://github.com/nodejs/node/pull/10054 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
6281a1c3e3
commit
00da58db7e
@ -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() {
|
||||
@ -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();
|
||||
@ -67,6 +65,5 @@ function makeRequest() {
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.equal(1024 * 10240, count);
|
||||
assert.ok(clientReqComplete);
|
||||
assert.strictEqual(1024 * 10240, count);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user