8000 test: fix flaky test-tls-multiple-cas-as-string · nodejs/node@b6e540a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit b6e540a

Browse files
lpincatargos
authored andcommitted
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: #27569 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
1 parent c53a674 commit b6e540a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

test/parallel/test-tls-multiple-cas-as-string.js

+18-15
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,29 @@ const ca2 = fixtures.readKey('ca2-cert.pem', 'utf8');
1515
const cert = fixtures.readKey('agent3-cert.pem', 'utf8');
1616
const key = fixtures.readKey('agent3-key.pem', 'utf8');
1717

18-
function test(ca, next) {
19-
const server = tls.createServer({ ca, cert, key }, function(conn) {
20-
this.close();
21-
conn.end();
22-
});
18+
function test(ca) {
19+
const server = tls.createServer({ ca, cert, key });
2320

2421
server.addContext('agent3', { ca, cert, key });
2522

2623
const host = common.localhostIPv4;
27-
server.listen(0, host, function() {
28-
tls.connect({ servername: 'agent3', host, port: this.address().port, ca });
29-
});
30-
31-
if (next) {
32-
server.once('close', next);
33-
}
24+
server.listen(0, host, common.mustCall(() => {
25+
const socket = tls.connect({
26+
servername: 'agent3',
27+
host,
28+
port: server.address().port,
29+
ca
30+
}, common.mustCall(() => {
31+
socket.end();
32+
}));
33+
34+
socket.on('close', () => {
35+
server.close();
36+
});
37+
}));
3438
}
3539

3640
// `ca1` is not actually necessary for the certificate validation -- maybe
3741
// the fixtures should be written in a way that requires it?
38-
const array = [ca1, ca2];
39-
const string = `${ca1}\n${ca2}`;
40-
test(array, common.mustCall(() => test(string)));
42+
test([ca1, ca2]);
43+
test(`${ca1}\n${ca2}`);

0 commit comments

Comments
 (0)
0