test: improve test-http-allow-req-after-204-res
* use const instead of var * use common.mustCall to control functions execution * use assert.strictEqual instead of assert.equal * use arrow functions PR-URL: https://github.com/nodejs/node/pull/10503 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
f60aba2fd4
commit
509ff1b9e4
@ -1,35 +1,32 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
var http = require('http');
|
const http = require('http');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
// first 204 or 304 works, subsequent anything fails
|
// first 204 or 304 works, subsequent anything fails
|
||||||
var codes = [204, 200];
|
const codes = [204, 200];
|
||||||
|
|
||||||
// Methods don't really matter, but we put in something realistic.
|
// Methods don't really matter, but we put in something realistic.
|
||||||
var methods = ['DELETE', 'DELETE'];
|
const methods = ['DELETE', 'DELETE'];
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
const server = http.createServer(common.mustCall((req, res) => {
|
||||||
var code = codes.shift();
|
const code = codes.shift();
|
||||||
assert.equal('number', typeof code);
|
assert.strictEqual(typeof code, 'number');
|
||||||
assert.ok(code > 0);
|
assert.ok(code > 0);
|
||||||
console.error('writing %d response', code);
|
|
||||||
res.writeHead(code, {});
|
res.writeHead(code, {});
|
||||||
res.end();
|
res.end();
|
||||||
});
|
}, codes.length));
|
||||||
|
|
||||||
function nextRequest() {
|
function nextRequest() {
|
||||||
var method = methods.shift();
|
const method = methods.shift();
|
||||||
console.error('writing request: %s', method);
|
|
||||||
|
|
||||||
var request = http.request({
|
const request = http.request({
|
||||||
port: server.address().port,
|
port: server.address().port,
|
||||||
method: method,
|
method: method,
|
||||||
path: '/'
|
path: '/'
|
||||||
}, function(response) {
|
}, common.mustCall((response) => {
|
||||||
response.on('end', function() {
|
response.on('end', common.mustCall(() => {
|
||||||
if (methods.length === 0) {
|
if (methods.length === 0) {
|
||||||
console.error('close server');
|
|
||||||
server.close();
|
server.close();
|
||||||
} else {
|
} else {
|
||||||
// throws error:
|
// throws error:
|
||||||
@ -37,9 +34,9 @@ function nextRequest() {
|
|||||||
// works just fine:
|
// works just fine:
|
||||||
//process.nextTick(nextRequest);
|
//process.nextTick(nextRequest);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
response.resume();
|
response.resume();
|
||||||
});
|
}));
|
||||||
request.end();
|
request.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user