Skip to content

Commit e121d7d

Browse files
lpincamarco-ippolito
authored andcommitted
test: fix invalid common.mustSucceed() usage
By its own nature, the function returned by `common.mustSucceed()` cannot be used as a listener for `'error'` events. Write errors like `read ECONNRESET` or `write EPIPE`, should be ignored because the socket might be closed by the other peer while the request is sent. Refs: 3caa2c1a005652fdb3e8 PR-URL: #56756 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 11b82de commit e121d7d

6 files changed

+48
-36
lines changed

test/parallel/test-http-server-headers-timeout-delayed-headers.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ server.listen(0, common.mustCall(() => {
3838
response += chunk;
3939
}));
4040

41-
const errOrEnd = common.mustSucceed(function(err) {
41+
client.on('error', () => {
42+
// Ignore errors like 'write EPIPE' that might occur while the request is
43+
// sent.
44+
});
45+
46+
client.on('close', common.mustCall(() => {
4247
assert.strictEqual(
4348
response,
4449
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
4550
);
4651
server.close();
47-
});
48-
49-
client.on('end', errOrEnd);
50-
client.on('error', errOrEnd);
52+
}));
5153

5254
client.resume();
5355

test/parallel/test-http-server-headers-timeout-interrupted-headers.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ server.listen(0, common.mustCall(() => {
3838
response += chunk;
3939
}));
4040

41-
const errOrEnd = common.mustSucceed(function(err) {
41+
client.on('error', () => {
42+
// Ignore errors like 'write EPIPE' that might occur while the request is
43+
// sent.
44+
});
45+
46+
client.on('close', common.mustCall(() => {
4247
assert.strictEqual(
4348
response,
4449
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
4550
);
4651
server.close();
47-
});
48-
49-
client.on('end', errOrEnd);
50-
client.on('error', errOrEnd);
52+
}));
5153

5254
client.resume();
5355
client.write('GET / HTTP/1.1\r\n');

test/parallel/test-http-server-request-timeout-delayed-body.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ server.listen(0, common.mustCall(() => {
4545
response += chunk;
4646
}));
4747

48+
client.on('error', () => {
49+
// Ignore errors like 'write EPIPE' that might occur while the request is
50+
// sent.
51+
});
52+
53+
client.on('close', common.mustCall(() => {
54+
assert.strictEqual(
55+
response,
56+
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
57+
);
58+
server.close();
59+
}));
60+
4861
client.resume();
4962
client.write('POST / HTTP/1.1\r\n');
5063
client.write('Host: example.com\r\n');
@@ -57,15 +70,4 @@ server.listen(0, common.mustCall(() => {
5770
client.write('12345678901234567890\r\n\r\n');
5871
}, common.platformTimeout(requestTimeout * 2)).unref();
5972
});
60-
61-
const errOrEnd = common.mustSucceed(function(err) {
62-
assert.strictEqual(
63-
response,
64-
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
65-
);
66-
server.close();
67-
});
68-
69-
client.on('end', errOrEnd);
70-
client.on('error', errOrEnd);
7173
}));

test/parallel/test-http-server-request-timeout-delayed-headers.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ server.listen(0, common.mustCall(() => {
3333
response += chunk;
3434
}));
3535

36-
const errOrEnd = common.mustSucceed(function(err) {
36+
client.on('error', () => {
37+
// Ignore errors like 'write EPIPE' that might occur while the request is
38+
// sent.
39+
});
40+
41+
client.on('close', common.mustCall(() => {
3742
assert.strictEqual(
3843
response,
3944
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
4045
);
4146
server.close();
42-
});
43-
44-
client.on('end', errOrEnd);
45-
client.on('error', errOrEnd);
47+
}));
4648

4749
client.resume();
4850

test/parallel/test-http-server-request-timeout-interrupted-body.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,18 @@ server.listen(0, common.mustCall(() => {
4545
response += chunk;
4646
}));
4747

48-
const errOrEnd = common.mustSucceed(function(err) {
48+
client.on('error', () => {
49+
// Ignore errors like 'write EPIPE' that might occur while the request is
50+
// sent.
51+
});
52+
53+
client.on('close', common.mustCall(() => {
4954
assert.strictEqual(
5055
response,
5156
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
5257
);
5358
server.close();
54-
});
55-
56-
client.on('error', errOrEnd);
57-
client.on('end', errOrEnd);
59+
}));
5860

5961
client.resume();
6062
client.write('POST / HTTP/1.1\r\n');

test/parallel/test-http-server-request-timeout-interrupted-headers.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ server.listen(0, common.mustCall(() => {
3333
response += chunk;
3434
}));
3535

36-
const errOrEnd = common.mustSucceed(function(err) {
36+
client.on('error', () => {
37+
// Ignore errors like 'write EPIPE' that might occur while the request is
38+
// sent.
39+
});
40+
41+
client.on('close', common.mustCall(() => {
3742
assert.strictEqual(
3843
response,
3944
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
4045
);
4146
server.close();
42-
});
43-
44-
client.on('end', errOrEnd);
45-
client.on('error', errOrEnd);
47+
}));
4648

4749
client.resume();
4850
client.write('GET / HTTP/1.1\r\n');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy