Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5fae384

Browse files
committedApr 8, 2025·
fixup! attempt with force gc
1 parent 2105f15 commit 5fae384

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed
 

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

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --expose-gc
12
'use strict';
23
const common = require('../common');
34

@@ -22,19 +23,22 @@ const stringTooLongError = {
2223
const size = 2 ** 31;
2324

2425
// Test Buffer.toString
25-
const bufferMethodsToTest = [SlowBuffer, Buffer.alloc, Buffer.allocUnsafe, Buffer.allocUnsafeSlow];
26-
27-
bufferMethodsToTest.forEach((method) => {
28-
test(`${method.name} with too long size`, () => {
29-
try {
30-
assert.throws(() => method(size).toString('utf8'), stringTooLongError);
31-
} catch (e) {
32-
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
33-
throw e;
34-
}
35-
common.skip('insufficient space for Buffer.alloc');
26+
test('Buffer.toString with too long size', () => {
27+
try {
28+
assert.throws(() => SlowBuffer(size).toString('utf8'), stringTooLongError);
29+
globalThis.gc({type: 'major'});
30+
assert.throws(() => Buffer.alloc(size).toString('utf8'), stringTooLongError);
31+
globalThis.gc({type: 'major'});
32+
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), stringTooLongError);
33+
globalThis.gc({type: 'major'});
34+
assert.throws(() => Buffer.allocUnsafeSlow(size).toString('utf8'), stringTooLongError);
35+
globalThis.gc({type: 'major'});
36+
} catch (e) {
37+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
38+
throw e;
3639
}
37-
});
40+
common.skip('insufficient space for Buffer.alloc');
41+
}
3842
});
3943

4044
// Test Buffer.write
@@ -43,6 +47,7 @@ test('Buffer.write with too long size', () => {
4347
const buf = Buffer.alloc(size);
4448
assert.strictEqual(buf.write('a', 2, kStringMaxLength), 1);
4549
assert.strictEqual(buf.write('a', 2, size), 1);
50+
globalThis.gc({type: 'major'});
4651
} catch (e) {
4752
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
4853
throw e;

0 commit comments

Comments
 (0)
Please sign in to comment.