test: fix flaky test-tls-multiple-cas-as-string
The following error is emitted in a nondeterministic way on the server side socket on macOS: ``` events.js:173 throw er; // Unhandled 'error' event ^ Error: read ECONNRESET at TLSWrap.onStreamRead (internal/stream_base_commons.js:183:27) Emitted 'error' event at: at emitErrorNT (internal/streams/destroy.js:91:8) at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) at processTicksAndRejections (internal/process/task_queues.js:84:9) ``` Prevent the error from being emitted by moving the `socket.end()` call to the client. Also, run tests in parallel and use `common.mustCall()`. PR-URL: https://github.com/nodejs/node/pull/27569 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit is contained in:
parent
e006a8545e
commit
a681d95a30
@ -15,26 +15,29 @@ const ca2 = fixtures.readKey('ca2-cert.pem', 'utf8');
|
|||||||
const cert = fixtures.readKey('agent3-cert.pem', 'utf8');
|
const cert = fixtures.readKey('agent3-cert.pem', 'utf8');
|
||||||
const key = fixtures.readKey('agent3-key.pem', 'utf8');
|
const key = fixtures.readKey('agent3-key.pem', 'utf8');
|
||||||
|
|
||||||
function test(ca, next) {
|
function test(ca) {
|
||||||
const server = tls.createServer({ ca, cert, key }, function(conn) {
|
const server = tls.createServer({ ca, cert, key });
|
||||||
this.close();
|
|
||||||
conn.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
server.addContext('agent3', { ca, cert, key });
|
server.addContext('agent3', { ca, cert, key });
|
||||||
|
|
||||||
const host = common.localhostIPv4;
|
const host = common.localhostIPv4;
|
||||||
server.listen(0, host, function() {
|
server.listen(0, host, common.mustCall(() => {
|
||||||
tls.connect({ servername: 'agent3', host, port: this.address().port, ca });
|
const socket = tls.connect({
|
||||||
});
|
servername: 'agent3',
|
||||||
|
host,
|
||||||
|
port: server.address().port,
|
||||||
|
ca
|
||||||
|
}, common.mustCall(() => {
|
||||||
|
socket.end();
|
||||||
|
}));
|
||||||
|
|
||||||
if (next) {
|
socket.on('close', () => {
|
||||||
server.once('close', next);
|
server.close();
|
||||||
}
|
});
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// `ca1` is not actually necessary for the certificate validation -- maybe
|
// `ca1` is not actually necessary for the certificate validation -- maybe
|
||||||
// the fixtures should be written in a way that requires it?
|
// the fixtures should be written in a way that requires it?
|
||||||
const array = [ca1, ca2];
|
test([ca1, ca2]);
|
||||||
const string = `${ca1}\n${ca2}`;
|
test(`${ca1}\n${ca2}`);
|
||||||
test(array, common.mustCall(() => test(string)));
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user