Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: deflake test-buffer-large-size
  • Loading branch information
jakecastelli committed Apr 9, 2025
commit e6b2341d0dc548628e0445f81befe3f573ecfa78
30 changes: 30 additions & 0 deletions test/pummel/test-buffer-large-size-buffer-alloc-unsafe-slow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'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 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',
};
Comment thread
jakecastelli marked this conversation as resolved.
Outdated

const size = 2 ** 31;

test('Buffer.allocUnsafeSlow with too long size', () => {
Comment thread
RaisinTen marked this conversation as resolved.
Outdated
try {
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.allocUnsafeSlow');
}
});
30 changes: 30 additions & 0 deletions test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'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 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.allocUnsafe with too long size', () => {
try {
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), stringTooLongError);
} catch (e) {
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
throw e;
}
common.skip('insufficient space for Buffer.allocUnsafe');
}
});
30 changes: 30 additions & 0 deletions test/pummel/test-buffer-large-size-buffer-alloc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'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 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.alloc too long size', () => {
try {
assert.throws(() => Buffer.alloc(size).toString('utf8'), stringTooLongError);
} catch (e) {
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
throw e;
}
common.skip('insufficient space for Buffer.alloc');
}
});
25 changes: 25 additions & 0 deletions test/pummel/test-buffer-large-size-buffer-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'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 kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;

const size = 2 ** 31;

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');
}
});
33 changes: 33 additions & 0 deletions test/pummel/test-buffer-large-size-slowbuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'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('SlowBuffer.toString with too long size', () => {
try {
assert.throws(() => SlowBuffer(size).toString('utf8'), stringTooLongError);
} catch (e) {
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
throw e;
}
common.skip('insufficient space for SlowBuffer');
}
});
51 changes: 0 additions & 51 deletions test/pummel/test-buffer-large-size.js

This file was deleted.

Loading