mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
test: deflake test-buffer-large-size
PR-URL: https://github.com/nodejs/node/pull/57789 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d5b3dbb0f5
commit
795dd8eb79
|
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
// Buffer with size > INT32_MAX
|
||||
common.skipIf32Bits();
|
||||
|
||||
const assert = require('node:assert');
|
||||
const size = 2 ** 31;
|
||||
|
||||
// Test Buffer.allocUnsafe with size larger than integer range
|
||||
try {
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
|
||||
} catch (e) {
|
||||
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
|
||||
throw e;
|
||||
}
|
||||
common.skip('insufficient space for Buffer.allocUnsafeSlow');
|
||||
}
|
||||
18
test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js
Normal file
18
test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
// Buffer with size > INT32_MAX
|
||||
common.skipIf32Bits();
|
||||
|
||||
const assert = require('node:assert');
|
||||
const size = 2 ** 31;
|
||||
|
||||
try {
|
||||
// Test Buffer.allocUnsafe with size larger than integer range
|
||||
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
|
||||
} catch (e) {
|
||||
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
|
||||
throw e;
|
||||
}
|
||||
common.skip('insufficient space for Buffer.allocUnsafe');
|
||||
}
|
||||
18
test/pummel/test-buffer-large-size-buffer-alloc.js
Normal file
18
test/pummel/test-buffer-large-size-buffer-alloc.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
// Buffer with size > INT32_MAX
|
||||
common.skipIf32Bits();
|
||||
|
||||
const assert = require('node:assert');
|
||||
const size = 2 ** 31;
|
||||
|
||||
// Test Buffer.alloc with size larger than integer range
|
||||
try {
|
||||
assert.throws(() => Buffer.alloc(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
|
||||
} catch (e) {
|
||||
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
|
||||
throw e;
|
||||
}
|
||||
common.skip('insufficient space for Buffer.alloc');
|
||||
}
|
||||
22
test/pummel/test-buffer-large-size-buffer-write.js
Normal file
22
test/pummel/test-buffer-large-size-buffer-write.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
// Buffer with size > INT32_MAX
|
||||
common.skipIf32Bits();
|
||||
|
||||
const assert = require('node:assert');
|
||||
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
|
||||
|
||||
const size = 2 ** 31;
|
||||
|
||||
// Test Buffer.write with size larger than integer range
|
||||
try {
|
||||
const buf = Buffer.alloc(size);
|
||||
assert.strictEqual(buf.write('a', 2, kStringMaxLength), 1);
|
||||
assert.strictEqual(buf.write('a', 2, size), 1);
|
||||
} catch (e) {
|
||||
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
|
||||
throw e;
|
||||
}
|
||||
common.skip('insufficient space for Buffer.alloc');
|
||||
}
|
||||
22
test/pummel/test-buffer-large-size-slowbuffer.js
Normal file
22
test/pummel/test-buffer-large-size-slowbuffer.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
// Buffer with size > INT32_MAX
|
||||
common.skipIf32Bits();
|
||||
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
SlowBuffer,
|
||||
} = require('node:buffer');
|
||||
|
||||
const size = 2 ** 31;
|
||||
|
||||
// Test SlowBuffer with size larger than integer range
|
||||
try {
|
||||
assert.throws(() => SlowBuffer(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
|
||||
} catch (e) {
|
||||
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
|
||||
throw e;
|
||||
}
|
||||
common.skip('insufficient space for SlowBuffer');
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
// Buffer with size > INT32_MAX
|
||||
common.skipIf32Bits();
|
||||
|
||||
// Test Buffer size larger than integer range
|
||||
const { test } = require('node:test');
|
||||
const assert = require('assert');
|
||||
const {
|
||||
SlowBuffer,
|
||||
} = require('buffer');
|
||||
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
|
||||
|
||||
const stringTooLongError = {
|
||||
message: `Cannot create a string longer than 0x${kStringMaxLength.toString(16)}` +
|
||||
' characters',
|
||||
code: 'ERR_STRING_TOO_LONG',
|
||||
name: 'Error',
|
||||
};
|
||||
|
||||
const size = 2 ** 31;
|
||||
|
||||
// Test Buffer.toString
|
||||
test('Buffer.toString with too long size', () => {
|
||||
try {
|
||||
assert.throws(() => SlowBuffer(size).toString('utf8'), stringTooLongError);
|
||||
assert.throws(() => Buffer.alloc(size).toString('utf8'), stringTooLongError);
|
||||
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), stringTooLongError);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(size).toString('utf8'), stringTooLongError);
|
||||
} catch (e) {
|
||||
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
|
||||
throw e;
|
||||
}
|
||||
common.skip('insufficient space for Buffer.alloc');
|
||||
}
|
||||
});
|
||||
|
||||
// Test Buffer.write
|
||||
test('Buffer.write with too long size', () => {
|
||||
try {
|
||||
const buf = Buffer.alloc(size);
|
||||
assert.strictEqual(buf.write('a', 2, kStringMaxLength), 1);
|
||||
assert.strictEqual(buf.write('a', 2, size), 1);
|
||||
} catch (e) {
|
||||
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
|
||||
throw e;
|
||||
}
|
||||
common.skip('insufficient space for Buffer.alloc');
|
||||
}
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user