Skip to content

Commit 660d238

Browse files
jakecastelliRafaelGSS
authored andcommitted
test: deflake test-buffer-large-size
PR-URL: #57789 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 82bb228 commit 660d238

6 files changed

Lines changed: 98 additions & 51 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
constassert=require('node:assert');
8+
constsize=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+
throwe;
16+
}
17+
common.skip('insufficient space for Buffer.allocUnsafeSlow');
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
constassert=require('node:assert');
8+
constsize=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+
throwe;
16+
}
17+
common.skip('insufficient space for Buffer.allocUnsafe');
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
constassert=require('node:assert');
8+
constsize=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+
throwe;
16+
}
17+
common.skip('insufficient space for Buffer.alloc');
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
constassert=require('node:assert');
8+
constkStringMaxLength=require('buffer').constants.MAX_STRING_LENGTH;
9+
10+
constsize=2**31;
11+
12+
// Test Buffer.write with size larger than integer range
13+
try{
14+
constbuf=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+
throwe;
20+
}
21+
common.skip('insufficient space for Buffer.alloc');
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
4+
// Buffer with size > INT32_MAX
5+
common.skipIf32Bits();
6+
7+
constassert=require('node:assert');
8+
const{
9+
SlowBuffer,
10+
}=require('node:buffer');
11+
12+
constsize=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+
throwe;
20+
}
21+
common.skip('insufficient space for SlowBuffer');
22+
}

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

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)