node/test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js
Luigi Pinca d7becc5875
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
PR-URL: https://github.com/nodejs/node/pull/58771
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Dario Piotrowicz <dario.piotrowicz@gmail.com>
2025-06-22 09:43:35 +00:00

28 lines
596 B
JavaScript

'use strict';
const common = require('../common');
// Buffer with size > INT32_MAX
common.skipIf32Bits();
const assert = require('node:assert');
const size = 2 ** 31;
let largeBuffer;
// Test Buffer.allocUnsafe with size larger than integer range
try {
largeBuffer = Buffer.allocUnsafe(size);
} catch (e) {
if (
e.code === 'ERR_MEMORY_ALLOCATION_FAILED' ||
/Array buffer allocation failed/.test(e.message)
) {
common.skip('insufficient space for Buffer.allocUnsafe');
}
throw e;
}
assert.throws(() => largeBuffer.toString('utf8'), {
code: 'ERR_STRING_TOO_LONG',
});