Skip to content

Commit 795dd8e

Browse files
authored
test: deflake test-buffer-large-size
PR-URL: #57789 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d5b3dbb commit 795dd8e

6 files changed

+98
-51
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
const assert = require('node:assert');
8+
const size = 2 ** 31;
9+
10+
// Test Buffer.allocUnsafe with size larger than integer range
11+
try {
12+
assert.throws(() => Buffer.allocUnsafeSlow(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
13+
} catch (e) {
14+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
15+
throw e;
16+
}
17+
common.skip('insufficient space for Buffer.allocUnsafeSlow');
18+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
const assert = require('node:assert');
8+
const size = 2 ** 31;
9+
10+
try {
11+
// Test Buffer.allocUnsafe with size larger than integer range
12+
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
13+
} catch (e) {
14+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
15+
throw e;
16+
}
17+
common.skip('insufficient space for Buffer.allocUnsafe');
18+
}

Diff for: test/pummel/test-buffer-large-size-buffer-alloc.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
const assert = require('node:assert');
8+
const size = 2 ** 31;
9+
10+
// Test Buffer.alloc with size larger than integer range
11+
try {
12+
assert.throws(() => Buffer.alloc(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
13+
} catch (e) {
14+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
15+
throw e;
16+
}
17+
common.skip('insufficient space for Buffer.alloc');
18+
}

Diff for: test/pummel/test-buffer-large-size-buffer-write.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
const assert = require('node:assert');
8+
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
9+
10+
const size = 2 ** 31;
11+
12+
// Test Buffer.write with size larger than integer range
13+
try {
14+
const buf = Buffer.alloc(size);
15+
assert.strictEqual(buf.write('a', 2, kStringMaxLength), 1);
16+
assert.strictEqual(buf.write('a', 2, size), 1);
17+
} catch (e) {
18+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
19+
throw e;
20+
}
21+
common.skip('insufficient space for Buffer.alloc');
22+
}

Diff for: test/pummel/test-buffer-large-size-slowbuffer.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
const assert = require('node:assert');
8+
const {
9+
SlowBuffer,
10+
} = require('node:buffer');
11+
12+
const size = 2 ** 31;
13+
14+
// Test SlowBuffer with size larger than integer range
15+
try {
16+
assert.throws(() => SlowBuffer(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
17+
} catch (e) {
18+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
19+
throw e;
20+
}
21+
common.skip('insufficient space for SlowBuffer');
22+
}

Diff for: test/pummel/test-buffer-large-size.js

-51
This file was deleted.

0 commit comments

Comments
 (0)