diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js index fcf5279dd3ce..87a754cb216d 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js index 6aff04451956..e03b5ae0352a 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js index 7c8e2d92c6a4..9ffff4fdbbee 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js index 176c095e22e2..c962c491d0c6 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js @@ -18,7 +18,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js index a473e0e90fb2..1cef739c5c36 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js index 25271fad94b6..2e00ff497225 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js index 121ca2d62bae..6fbc52849c47 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 2); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js index b843be5a9ab7..e13f865405ce 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/parallel/test-http-agent-keepalive.js b/test/parallel/test-http-agent-keepalive.js index ca50fa40bf22..48596e6caeb3 100644 --- a/test/parallel/test-http-agent-keepalive.js +++ b/test/parallel/test-http-agent-keepalive.js @@ -94,13 +94,13 @@ function remoteClose() { assert.strictEqual(agent.sockets[name], undefined); assert.strictEqual(agent.freeSockets[name].length, 1); assert.strictEqual(agent.totalSocketCount, 1); - // Waiting remote server close the socket - setTimeout(common.mustCall(() => { + // Wait for the remote server to close the socket. + req.socket.once('close', common.mustCall(() => { assert.strictEqual(agent.sockets[name], undefined); assert.strictEqual(agent.freeSockets[name], undefined); assert.strictEqual(agent.totalSocketCount, 0); remoteError(); - }), common.platformTimeout(200)); + })); })); })); })); @@ -115,13 +115,13 @@ function remoteError() { assert.strictEqual(agent.sockets[name].length, 1); assert.strictEqual(agent.freeSockets[name], undefined); assert.strictEqual(agent.totalSocketCount, 1); - // Wait socket 'close' event emit - setTimeout(common.mustCall(() => { + // Wait for the socket's 'close' event. + req.socket.once('close', common.mustCall(() => { assert.strictEqual(agent.sockets[name], undefined); assert.strictEqual(agent.freeSockets[name], undefined); assert.strictEqual(agent.totalSocketCount, 0); server.close(); - }), common.platformTimeout(1)); + })); })); }