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: improve test-http-allow-req-after-204-res #10503

Closed
wants to merge 1 commit into from
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
33 changes: 15 additions & 18 deletions test/parallel/test-http-allow-req-after-204-res.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
'use strict';
require('../common');
var http = require('http');
var assert = require('assert');
const common = require('../common');
const http = require('http');
const assert = require('assert');

// 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.
var methods = ['DELETE', 'DELETE'];
const methods = ['DELETE', 'DELETE'];

var server = http.createServer(function(req, res) {
var code = codes.shift();
assert.equal('number', typeof code);
const server = http.createServer(common.mustCall((req, res) => {
const code = codes.shift();
assert.strictEqual(typeof code, 'number');
assert.ok(code > 0);
console.error('writing %d response', code);
res.writeHead(code, {});
res.end();
});
}, codes.length));

function nextRequest() {
var method = methods.shift();
console.error('writing request: %s', method);
const method = methods.shift();

var request = http.request({
const request = http.request({
port: server.address().port,
method: method,
path: '/'
}, function(response) {
response.on('end', function() {
}, common.mustCall((response) => {
response.on('end', common.mustCall(() => {
if (methods.length === 0) {
console.error('close server');
server.close();
} else {
// throws error:
nextRequest();
// works just fine:
//process.nextTick(nextRequest);
}
});
}));
response.resume();
});
}));
request.end();
}

Expand Down