From c54cee1c3f604d87ee4a7317bd14fca8575acbb1 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Sun, 2 Oct 2022 14:10:37 +0100 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. PR-URL: https://github.com/nodejs/node/pull/44824 Refs: https://github.com/nodejs/node/issues/44821 Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott Reviewed-By: James M Snell --- 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);