mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
test: fix test-buffer-tostring-range on allocation failure
If the test cannot allocate a buffer over 4GB, there is no point continue testing toString() on it. This also split the test case to a different file for clarity and reduce interference with other cases. PR-URL: https://github.com/nodejs/node/pull/58416 Fixes: https://github.com/nodejs/node/issues/56726 Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
This commit is contained in:
parent
996a774eba
commit
e9c6004a2d
20
test/parallel/test-buffer-tostring-4gb.js
Normal file
20
test/parallel/test-buffer-tostring-4gb.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
// This tests that Buffer.prototype.toString() works with buffers over 4GB.
|
||||
const common = require('../common');
|
||||
|
||||
// Must not throw when start and end are within kMaxLength
|
||||
// Cannot test on 32bit machine as we are testing the case
|
||||
// when start and end are above the threshold
|
||||
common.skipIf32Bits();
|
||||
const threshold = 0xFFFFFFFF; // 2^32 - 1
|
||||
let largeBuffer;
|
||||
try {
|
||||
largeBuffer = Buffer.alloc(threshold + 20);
|
||||
} catch (e) {
|
||||
if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || /Array buffer allocation failed/.test(e.message)) {
|
||||
common.skip('insufficient space for Buffer.alloc');
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
largeBuffer.toString('utf8', threshold, threshold + 20);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const rangeBuffer = Buffer.from('abc');
|
||||
|
|
@ -98,11 +98,3 @@ assert.throws(() => {
|
|||
name: 'TypeError',
|
||||
message: 'Unknown encoding: null'
|
||||
});
|
||||
|
||||
// Must not throw when start and end are within kMaxLength
|
||||
// Cannot test on 32bit machine as we are testing the case
|
||||
// when start and end are above the threshold
|
||||
common.skipIf32Bits();
|
||||
const threshold = 0xFFFFFFFF;
|
||||
const largeBuffer = Buffer.alloc(threshold + 20);
|
||||
largeBuffer.toString('utf8', threshold, threshold + 20);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user