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: check types for http request and response #7003

Merged
merged 1 commit into from
Jun 29, 2016
Merged
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
55 changes: 55 additions & 0 deletions test/parallel/test-http-same-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Flags: --allow_natives_syntax
'use strict';

const common = require('../common');
const assert = require('assert');
const http = require('http');

const server =
http.createServer(onrequest).listen(0, common.localhostIPv4, () => next(0));

function onrequest(req, res) {
res.end('ok');
onrequest.requests.push(req);
onrequest.responses.push(res);
}
onrequest.requests = [];
onrequest.responses = [];

function next(n) {
const { address: host, port } = server.address();
const req = http.get({ host, port });
req.once('response', (res) => onresponse(n, req, res));
}

function onresponse(n, req, res) {
res.resume();

if (n < 3) {
res.once('end', () => next(n + 1));
} else {
server.close();
}

onresponse.requests.push(req);
onresponse.responses.push(res);
}
onresponse.requests = [];
onresponse.responses = [];

function allSame(list) {
assert(list.length >= 2);
// Use |elt| in no-op position to pacify eslint.
for (const elt of list) elt, eval('%DebugPrint(elt)');
for (const elt of list) elt, assert(eval('%HaveSameMap(list[0], elt)'));
}

process.on('exit', () => {
eval('%CollectGarbage(0)');
// TODO(bnoordhuis) Investigate why the first IncomingMessage ends up
// with a deprecated map. The map is stable after the first request.
allSame(onrequest.requests.slice(1));
allSame(onrequest.responses);
allSame(onresponse.requests);
allSame(onresponse.responses);
});