mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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: https://github.com/nodejs/node/commit/3caa2c1a005652fdb3e8 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
@@ -38,16 +38,18 @@ server.listen(0, common.mustCall(() => {
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
client.on('error', () => {
|
||||
// Ignore errors like 'write EPIPE' that might occur while the request is
|
||||
// sent.
|
||||
});
|
||||
|
||||
client.on('close', common.mustCall(() => {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
});
|
||||
|
||||
client.on('end', errOrEnd);
|
||||
client.on('error', errOrEnd);
|
||||
}));
|
||||
|
||||
client.resume();
|
||||
|
||||
|
||||
@@ -38,16 +38,18 @@ server.listen(0, common.mustCall(() => {
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
client.on('error', () => {
|
||||
// Ignore errors like 'write EPIPE' that might occur while the request is
|
||||
// sent.
|
||||
});
|
||||
|
||||
client.on('close', common.mustCall(() => {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
});
|
||||
|
||||
client.on('end', errOrEnd);
|
||||
client.on('error', errOrEnd);
|
||||
}));
|
||||
|
||||
client.resume();
|
||||
client.write('GET / HTTP/1.1\r\n');
|
||||
|
||||
@@ -45,6 +45,19 @@ server.listen(0, common.mustCall(() => {
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
client.on('error', () => {
|
||||
// Ignore errors like 'write EPIPE' that might occur while the request is
|
||||
// sent.
|
||||
});
|
||||
|
||||
client.on('close', common.mustCall(() => {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
}));
|
||||
|
||||
client.resume();
|
||||
client.write('POST / HTTP/1.1\r\n');
|
||||
client.write('Host: example.com\r\n');
|
||||
@@ -57,15 +70,4 @@ server.listen(0, common.mustCall(() => {
|
||||
client.write('12345678901234567890\r\n\r\n');
|
||||
}, common.platformTimeout(requestTimeout * 2)).unref();
|
||||
});
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
});
|
||||
|
||||
client.on('end', errOrEnd);
|
||||
client.on('error', errOrEnd);
|
||||
}));
|
||||
|
||||
@@ -33,16 +33,18 @@ server.listen(0, common.mustCall(() => {
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
client.on('error', () => {
|
||||
// Ignore errors like 'write EPIPE' that might occur while the request is
|
||||
// sent.
|
||||
});
|
||||
|
||||
client.on('close', common.mustCall(() => {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
});
|
||||
|
||||
client.on('end', errOrEnd);
|
||||
client.on('error', errOrEnd);
|
||||
}));
|
||||
|
||||
client.resume();
|
||||
|
||||
|
||||
@@ -45,16 +45,18 @@ server.listen(0, common.mustCall(() => {
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
client.on('error', () => {
|
||||
// Ignore errors like 'write EPIPE' that might occur while the request is
|
||||
// sent.
|
||||
});
|
||||
|
||||
client.on('close', common.mustCall(() => {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
});
|
||||
|
||||
client.on('error', errOrEnd);
|
||||
client.on('end', errOrEnd);
|
||||
}));
|
||||
|
||||
client.resume();
|
||||
client.write('POST / HTTP/1.1\r\n');
|
||||
|
||||
@@ -33,16 +33,18 @@ server.listen(0, common.mustCall(() => {
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
const errOrEnd = common.mustSucceed(function(err) {
|
||||
client.on('error', () => {
|
||||
// Ignore errors like 'write EPIPE' that might occur while the request is
|
||||
// sent.
|
||||
});
|
||||
|
||||
client.on('close', common.mustCall(() => {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
});
|
||||
|
||||
client.on('end', errOrEnd);
|
||||
client.on('error', errOrEnd);
|
||||
}));
|
||||
|
||||
client.resume();
|
||||
client.write('GET / HTTP/1.1\r\n');
|
||||
|
||||
Reference in New Issue
Block a user