mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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>
This commit is contained in:
parent
dfcb824ae3
commit
d7becc5875
1 changed files with 15 additions and 5 deletions
|
@ -7,12 +7,22 @@ common.skipIf32Bits();
|
|||
const assert = require('node:assert');
|
||||
const size = 2 ** 31;
|
||||
|
||||
try {
|
||||
let largeBuffer;
|
||||
|
||||
// Test Buffer.allocUnsafe with size larger than integer range
|
||||
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
|
||||
try {
|
||||
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');
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
assert.throws(() => largeBuffer.toString('utf8'), {
|
||||
code: 'ERR_STRING_TOO_LONG',
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue