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';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var http = require('http');
|
const http = require('http');
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var cp = require('child_process');
|
const cp = require('child_process');
|
||||||
|
|
||||||
common.refreshTmpDir();
|
common.refreshTmpDir();
|
||||||
|
|
||||||
var filename = path.join(common.tmpDir || '/tmp', 'big');
|
const filename = path.join(common.tmpDir || '/tmp', 'big');
|
||||||
var clientReqComplete = false;
|
let count = 0;
|
||||||
var count = 0;
|
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
const server = http.createServer(function(req, res) {
|
||||||
var timeoutId;
|
let timeoutId;
|
||||||
assert.equal('POST', req.method);
|
assert.strictEqual('POST', req.method);
|
||||||
req.pause();
|
req.pause();
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@ -36,27 +35,26 @@ var server = http.createServer(function(req, res) {
|
|||||||
server.listen(0);
|
server.listen(0);
|
||||||
|
|
||||||
server.on('listening', function() {
|
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;
|
if (err) throw err;
|
||||||
makeRequest();
|
makeRequest();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function makeRequest() {
|
function makeRequest() {
|
||||||
var req = http.request({
|
const req = http.request({
|
||||||
port: server.address().port,
|
port: server.address().port,
|
||||||
path: '/',
|
path: '/',
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
});
|
});
|
||||||
|
|
||||||
var s = fs.ReadStream(filename);
|
const s = fs.ReadStream(filename);
|
||||||
s.pipe(req);
|
s.pipe(req);
|
||||||
s.on('close', function(err) {
|
s.on('close', common.mustCall((err) => {
|
||||||
if (err) throw err;
|
assert.ifError(err);
|
||||||
clientReqComplete = true;
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
req.on('response', function(res) {
|
req.on('response', function(res) {
|
||||||
res.resume();
|
res.resume();
|
||||||
@ -67,6 +65,5 @@ function makeRequest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
assert.equal(1024 * 10240, count);
|
assert.strictEqual(1024 * 10240, count);
|
||||||
assert.ok(clientReqComplete);
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user