summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2016-05-26 18:45:18 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2016-06-29 18:13:35 +0200
commitdac16d8fb60a2aaf36f9a0a5174d04afbeef7f51 (patch)
treeeff2899dfcff47a4af223ce717c54172e43bac87 /test
parent92dab4a2b24bf9d092485b09868ac3183c8998f8 (diff)
downloadnode-new-dac16d8fb60a2aaf36f9a0a5174d04afbeef7f51.tar.gz
test: check types for http request and response
Add a basic regression test that checks if the map for IncomingMessage and OutgoingMessage objects is stable over time. The test is not exhaustive in that it doesn't try to establish whether the transition path is the same on every request, it just checks that objects in their final states have the same map. To be investigated why the first (and only the first) ServerRequest object ends up with a deprecated map, regardless of the number of iterations. PR-URL: https://github.com/nodejs/node/pull/7003 Refs: https://github.com/nodejs/node/issues/6294 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http-same-map.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/parallel/test-http-same-map.js b/test/parallel/test-http-same-map.js
new file mode 100644
index 0000000000..0adb73222d
--- /dev/null
+++ b/test/parallel/test-http-same-map.js
@@ -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);
+});