From c378768f76a8b5dbc9f5a699c86df8ceb3f68a0f Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Fri, 20 Jun 2025 11:38:48 +0200 Subject: [PATCH] test: deflake test-buffer-large-size-buffer-alloc-unsafe Use the error message as another condition to skip the test when the buffer allocation fails. Refs: https://github.com/nodejs/node/pull/58738 --- ...t-buffer-large-size-buffer-alloc-unsafe.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js b/test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js index 4002f60082d835..2aa1f0bccf4937 100644 --- a/test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js +++ b/test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js @@ -7,12 +7,22 @@ common.skipIf32Bits(); const assert = require('node:assert'); const size = 2 ** 31; +let largeBuffer; + +// Test Buffer.allocUnsafe with size larger than integer range try { - // Test Buffer.allocUnsafe with size larger than integer range - assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' }); + largeBuffer = Buffer.allocUnsafe(size); } catch (e) { - if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') { - throw e; + if ( + e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || + /Array buffer allocation failed/.test(e.message) + ) { + common.skip('insufficient space for Buffer.allocUnsafe'); } - common.skip('insufficient space for Buffer.allocUnsafe'); + + throw e; } + +assert.throws(() => largeBuffer.toString('utf8'), { + code: 'ERR_STRING_TOO_LONG', +});