Skip to content

Commit 3dae49c

Browse files
aduh95RafaelGSS
authored andcommitted
test: ensure assertions are reached on HTTP tests
PR-URL: #60729 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 5203b09 commit 3dae49c

147 files changed

Lines changed: 688 additions & 724 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎test/eslint.config_partial.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export default [
195195
`test/parallel/test-{${
196196
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
197197
Array.from({length: 4},(_,i)=>String.fromCharCode(0x61+i,42)).join(',')
198-
},${
198+
},http-*,${
199199
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
200200
Array.from({length: 5},(_,i)=>String.fromCharCode(0x61+25-i,42)).join(',')
201201
}}.{js,mjs,cjs}`,

‎test/parallel/test-http-1.0.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function test(handler, request_generator, response_validator) {
3434
letserver_response='';
3535

3636
server.listen(0);
37-
server.on('listening',function(){
37+
server.on('listening',common.mustCall(function(){
3838
constc=net.createConnection(this.address().port);
3939

4040
c.setEncoding('utf8');
@@ -53,7 +53,7 @@ function test(handler, request_generator, response_validator) {
5353
server.close();
5454
response_validator(server_response,client_got_eof,false);
5555
}));
56-
});
56+
}));
5757
}
5858

5959
{

‎test/parallel/test-http-abort-queued.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ server.listen(0, common.mustCall(() => {
5252
};
5353

5454
constreq1=http.request(options);
55-
req1.on('response',(res1)=>{
55+
req1.on('response',common.mustCall((res1)=>{
5656
assert.strictEqual(Object.keys(agent.sockets).length,1);
5757
assert.strictEqual(Object.keys(agent.requests).length,0);
5858

@@ -68,10 +68,10 @@ server.listen(0, common.mustCall(() => {
6868

6969
// TODO(jasnell): This event does not appear to currently be triggered.
7070
// is this handler actually required?
71-
req2.on('error',(err)=>{
71+
req2.on('error',common.mustCallAtLeast((err)=>{
7272
// This is expected in response to our explicit abort call
7373
assert.strictEqual(err.code,'ECONNRESET');
74-
});
74+
},0));
7575

7676
req2.end();
7777
req2.abort();
@@ -89,7 +89,7 @@ server.listen(0, common.mustCall(() => {
8989
server.close();
9090
}),100);
9191
}));
92-
});
92+
}));
9393

9494
req1.end();
9595
}));

‎test/parallel/test-http-abort-stream-end.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ const server = http.createServer(common.mustCall((req, res) => {
3838
res.end();
3939
}));
4040

41-
server.listen(0,()=>{
41+
server.listen(0,common.mustCall(()=>{
4242
constres=common.mustCall((res)=>{
43-
res.on('data',(chunk)=>{
43+
res.on('data',common.mustCallAtLeast((chunk)=>{
4444
size+=chunk.length;
4545
assert(!req.aborted,'got data after abort');
4646
if(size>maxSize){
4747
req.abort();
4848
assert.strictEqual(req.aborted,true);
4949
size=maxSize;
5050
}
51-
});
51+
}));
5252

5353
req.on('abort',common.mustCall(()=>assert.strictEqual(size,maxSize)));
5454
assert.strictEqual(req.aborted,false);
5555
});
5656

5757
constreq=http.get(`http://localhost:${server.address().port}`,res);
58-
});
58+
}));

‎test/parallel/test-http-agent-error-on-idle.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const server = http.createServer(common.mustCall((req, res) => {
99
res.end('hello world');
1010
},2));
1111

12-
server.listen(0,()=>{
12+
server.listen(0,common.mustCall(()=>{
1313
constagent=newAgent({keepAlive: true});
1414

1515
constrequestParams={
@@ -46,4 +46,4 @@ server.listen(0, () => {
4646
agent.destroy();
4747
server.close();
4848
}
49-
});
49+
}));

‎test/parallel/test-http-agent-keepalive-delay.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ const server = http.createServer(common.mustCall((req, res) => {
1616

1717
server.listen(0,common.mustCall(()=>{
1818
constcreateConnection=agent.createConnection;
19-
agent.createConnection=(options, ...args)=>{
19+
agent.createConnection=common.mustCall((options, ...args)=>{
2020
assert.strictEqual(options.keepAlive,true);
2121
assert.strictEqual(options.keepAliveInitialDelay,agent.keepAliveMsecs);
2222
returncreateConnection.call(agent,options, ...args);
23-
};
23+
});
2424
http.get({
2525
host: 'localhost',
2626
port: server.address().port,

‎test/parallel/test-http-agent-maxsockets.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function get(path, callback) {
2626
},callback);
2727
}
2828

29-
constcountdown=newCountdown(2,()=>{
29+
constcountdown=newCountdown(2,common.mustCall(()=>{
3030
constfreepool=agent.freeSockets[Object.keys(agent.freeSockets)[0]];
3131
assert.strictEqual(freepool.length,2,
3232
`expect keep 2 free sockets, but got ${freepool.length}`);
3333
agent.destroy();
3434
server.close();
35-
});
35+
}));
3636

3737
functiondec(){
3838
process.nextTick(()=>countdown.dec());

‎test/parallel/test-http-agent-maxtotalsockets.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ function start(param = {}) {
4848
server.keepAliveTimeout=0;
4949
server2.keepAliveTimeout=0;
5050

51-
constcountdown=newCountdown(12,()=>{
51+
constcountdown=newCountdown(12,common.mustCall(()=>{
5252
assert.strictEqual(getRequestCount(),0);
5353
agent.destroy();
5454
server.close();
5555
server2.close();
56-
});
56+
}));
5757

5858
functionhandler(s){
5959
for(leti=0;i<6;i++){

‎test/parallel/test-http-agent-remove.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const{ mustCall }=require('../common');
33

44
consthttp=require('http');
5-
const{ strictEqual }=require('assert');
5+
constassert=require('assert');
66

77
constserver=http.createServer(mustCall((req,res)=>{
88
res.flushHeaders();
@@ -14,7 +14,7 @@ server.listen(0, mustCall(() => {
1414
},mustCall(()=>{
1515
const{ socket }=req;
1616
socket.emit('agentRemove');
17-
strictEqual(socket._httpMessage,req);
17+
assert.strictEqual(socket._httpMessage,req);
1818
socket.destroy();
1919
server.close();
2020
}));

‎test/parallel/test-http-agent-reuse-drained-socket-only.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ function sendFstReq(serverPort) {
2828
agent,
2929
host: '127.0.0.1',
3030
port: serverPort,
31-
},(res)=>{
31+
},common.mustCall((res)=>{
3232
res.on('data',noop);
3333
res.on('end',common.mustCall(()=>{
3434
// Agent's socket reusing code is registered to process.nextTick(),
3535
// and will be run after this function, make sure it take effect.
3636
setImmediate(sendSecReq,serverPort,req.socket.localPort);
3737
}));
38-
});
38+
}));
3939

4040
// Make the `req.socket` non drained, i.e. has some data queued to write to
4141
// and accept by the kernel. In Linux and Mac, we only need to call `req.end(aLargeBuffer)`.
@@ -60,8 +60,8 @@ function sendFstReq(serverPort) {
6060
* back the socket within SO_SNDBUF quota or only one outstanding send condition.
6161
*/
6262

63-
req.on('socket',()=>{
64-
req.socket.on('connect',()=>{
63+
req.on('socket',common.mustCall(()=>{
64+
req.socket.on('connect',common.mustCall(()=>{
6565
// Print tcp send buffer information
6666
console.log(process.report.getReport().libuv.filter((handle)=>handle.type==='tcp'));
6767

@@ -81,8 +81,8 @@ function sendFstReq(serverPort) {
8181

8282
req.end(dataLargerThanTCPSendBuf);
8383
assert.ok(req.socket.writableLength>0);
84-
});
85-
});
84+
}));
85+
}));
8686
}
8787

8888
functionsendSecReq(serverPort,fstReqCliPort){
@@ -92,12 +92,12 @@ function sendSecReq(serverPort, fstReqCliPort) {
9292
agent,
9393
host: '127.0.0.1',
9494
port: serverPort,
95-
},(res)=>{
95+
},common.mustCall((res)=>{
9696
res.on('data',noop);
9797
res.on('end',common.mustCall(()=>{
9898
setImmediate(sendThrReq,serverPort,req.socket.localPort);
9999
}));
100-
});
100+
}));
101101

102102
req.on('socket',common.mustCall((sock)=>{
103103
assert.notStrictEqual(sock.localPort,fstReqCliPort);

0 commit comments

Comments
 (0)