Skip to content

Commit d7becc5

Browse files
authored
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: #58738 PR-URL: #58771 Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Dario Piotrowicz <[email protected]>
1 parent dfcb824 commit d7becc5

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 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+
12+
// Test Buffer.allocUnsafe with size larger than integer range
1013
try {
11-
// Test Buffer.allocUnsafe with size larger than integer range
12-
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
14+
largeBuffer = Buffer.allocUnsafe(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.allocUnsafe');
1621
}
17-
common.skip('insufficient space for Buffer.allocUnsafe');
22+
23+
throw e;
1824
}
25+
26+
assert.throws(() => largeBuffer.toString('utf8'), {
27+
code: 'ERR_STRING_TOO_LONG',
28+
});

0 commit comments

Comments
 (0)