From cff8e4693481a4cd529ca386e9330cb62ae05137 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Thu, 29 Sep 2022 13:01:05 -0400 Subject: [PATCH] test: check server status in test-tls-psk-client Add assertions to sequential/test-tls-psk-client to check if the spawned OpenSSL server has exited in any way except for the expected termination by the cleanUp() function. The added assertions will prevent the test from spinning forever trying to connect to the non-existent server in the case that the spawned process has exited. Include stderr and stdout in the assertion failure message to aid debugging. --- test/sequential/test-tls-psk-client.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/sequential/test-tls-psk-client.js b/test/sequential/test-tls-psk-client.js index 24d38d042938c0..cb15acd01fcccb 100644 --- a/test/sequential/test-tls-psk-client.js +++ b/test/sequential/test-tls-psk-client.js @@ -23,7 +23,18 @@ const server = spawn(common.opensslCli, [ '-psk_hint', IDENTITY, '-nocert', '-rev', -]); +], { encoding: 'utf8' }); +let serverErr = ''; +let serverOut = ''; +server.stderr.on('data', (data) => serverErr += data); +server.stdout.on('data', (data) => serverOut += data); +server.on('error', common.mustNotCall()); +server.on('exit', (code, signal) => { + // Server is expected to be terminated by cleanUp(). + assert.strictEqual(code, null, + `'${server.spawnfile} ${server.spawnargs.join(' ')}' unexpected exited with output:\n${serverOut}\n${serverErr}`); + assert.strictEqual(signal, 'SIGTERM'); +}); const cleanUp = (err) => { clearTimeout(timeout);