Skip to content

Commit 3399195

Browse files
tniessendanielleadams
authored andcommitted
test: simplify test-tls-ecdh-auto
Avoid the process 'exit' event handler and use execFile instead of manual stream operations. Refs: #46751 PR-URL: #46911 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent e52b169 commit 3399195

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

test/parallel/test-tls-ecdh-auto.js

+8-26
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (!common.opensslCli)
1212

1313
const assert = require('assert');
1414
const tls = require('tls');
15-
const spawn = require('child_process').spawn;
15+
const { execFile } = require('child_process');
1616
const fixtures = require('../common/fixtures');
1717

1818
function loadPEM(n) {
@@ -29,33 +29,15 @@ const options = {
2929

3030
const reply = 'I AM THE WALRUS'; // Something recognizable
3131

32-
const server = tls.createServer(options, function(conn) {
32+
const server = tls.createServer(options, (conn) => {
3333
conn.end(reply);
34-
});
35-
36-
let gotReply = false;
37-
38-
server.listen(0, function() {
34+
}).listen(0, common.mustCall(() => {
3935
const args = ['s_client',
4036
'-cipher', `${options.ciphers}`,
41-
'-connect', `127.0.0.1:${this.address().port}`];
42-
43-
const client = spawn(common.opensslCli, args);
37+
'-connect', `127.0.0.1:${server.address().port}`];
4438

45-
client.stdout.on('data', function(data) {
46-
const message = data.toString();
47-
if (message.includes(reply))
48-
gotReply = true;
49-
});
50-
51-
client.on('exit', function(code) {
52-
assert.strictEqual(code, 0);
39+
execFile(common.opensslCli, args, common.mustSucceed((stdout) => {
40+
assert(stdout.includes(reply));
5341
server.close();
54-
});
55-
56-
client.on('error', assert.ifError);
57-
});
58-
59-
process.on('exit', function() {
60-
assert.ok(gotReply);
61-
});
42+
}));
43+
}));

0 commit comments

Comments
 (0)