From 8f1319a53ea487c1b3e2a2d1d6908018e47eaf34 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 16 Jun 2025 22:04:28 +0200 Subject: [PATCH] test: deflake test-buffer-large-size-buffer-alloc Use the error message as another condition to skip the test when the buffer allocation fails. Refs: https://github.com/nodejs/node/commit/795dd8eb7988ae38553e Refs: https://github.com/nodejs/node/commit/e9c6004a2d580008082b --- .../test-buffer-large-size-buffer-alloc.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/pummel/test-buffer-large-size-buffer-alloc.js b/test/pummel/test-buffer-large-size-buffer-alloc.js index 00a989affc48d5..032818cc899975 100644 --- a/test/pummel/test-buffer-large-size-buffer-alloc.js +++ b/test/pummel/test-buffer-large-size-buffer-alloc.js @@ -7,12 +7,22 @@ common.skipIf32Bits(); const assert = require('node:assert'); const size = 2 ** 31; +let largeBuffer; + // Test Buffer.alloc with size larger than integer range try { - assert.throws(() => Buffer.alloc(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' }); + largeBuffer = Buffer.alloc(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.alloc'); } - common.skip('insufficient space for Buffer.alloc'); + + throw e; } + +assert.throws(() => largeBuffer.toString('utf8'), { + code: 'ERR_STRING_TOO_LONG', +});