Skip to content

Commit 214e4db

Browse files
authored
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: 795dd8eb7988ae38553e Refs: e9c6004a2d580008082b PR-URL: #58734 Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Stefan Stojanovic <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
1 parent 6f83e5d commit 214e4db

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

test/pummel/test-buffer-large-size-buffer-alloc.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@ common.skipIf32Bits();
77
const assert = require('node:assert');
88
const size = 2 ** 31;
99

10+
let largeBuffer;
11+
1012
// Test Buffer.alloc with size larger than integer range
1113
try {
12-
assert.throws(() => Buffer.alloc(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
14+
largeBuffer = Buffer.alloc(size);
1315
} catch (e) {
14-
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
15-
throw e;
16+
if (
17+
e.code === 'ERR_MEMORY_ALLOCATION_FAILED' ||
18+
/Array buffer allocation failed/.test(e.message)
19+
) {
20+
common.skip('insufficient space for Buffer.alloc');
1621
}
17-
common.skip('insufficient space for Buffer.alloc');
22+
23+
throw e;
1824
}
25+
26+
assert.throws(() => largeBuffer.toString('utf8'), {
27+
code: 'ERR_STRING_TOO_LONG',
28+
});

0 commit comments

Comments
 (0)