Skip to content

Commit 658ab3d

Browse files
bnoordhuisFishrock123
authored andcommitted
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: #7003 Refs: #6294 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 57cc4e3 commit 658ab3d

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Flags: --allow_natives_syntax
2+
'use strict';
3+
4+
constcommon=require('../common');
5+
constassert=require('assert');
6+
consthttp=require('http');
7+
8+
constserver=
9+
http.createServer(onrequest).listen(0,common.localhostIPv4,()=>next(0));
10+
11+
functiononrequest(req,res){
12+
res.end('ok');
13+
onrequest.requests.push(req);
14+
onrequest.responses.push(res);
15+
}
16+
onrequest.requests=[];
17+
onrequest.responses=[];
18+
19+
functionnext(n){
20+
const{address: host, port }=server.address();
21+
constreq=http.get({ host, port });
22+
req.once('response',(res)=>onresponse(n,req,res));
23+
}
24+
25+
functiononresponse(n,req,res){
26+
res.resume();
27+
28+
if(n<3){
29+
res.once('end',()=>next(n+1));
30+
}else{
31+
server.close();
32+
}
33+
34+
onresponse.requests.push(req);
35+
onresponse.responses.push(res);
36+
}
37+
onresponse.requests=[];
38+
onresponse.responses=[];
39+
40+
functionallSame(list){
41+
assert(list.length>=2);
42+
// Use |elt| in no-op position to pacify eslint.
43+
for(consteltoflist)elt,eval('%DebugPrint(elt)');
44+
for(consteltoflist)elt,assert(eval('%HaveSameMap(list[0], elt)'));
45+
}
46+
47+
process.on('exit',()=>{
48+
eval('%CollectGarbage(0)');
49+
// TODO(bnoordhuis) Investigate why the first IncomingMessage ends up
50+
// with a deprecated map. The map is stable after the first request.
51+
allSame(onrequest.requests.slice(1));
52+
allSame(onrequest.responses);
53+
allSame(onresponse.requests);
54+
allSame(onresponse.responses);
55+
});

0 commit comments

Comments
 (0)