Skip to content

Commit 7d94611

Browse files
committed
test: split up buffer tests for reliability
The Pi 1's in CI don't always fail on the buffer.toString() tests. But they time out sometimes, so let's split the tests up so they don't. PR-URL: #3323 Reviewed By: Evan Lucas <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed By: Trevor Norris <[email protected]>
1 parent bde32f8 commit 7d94611

5 files changed

+101
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
6+
// v8 fails silently if string length > v8::String::kMaxLength
7+
// v8::String::kMaxLength defined in v8.h
8+
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
9+
10+
try {
11+
new Buffer(kStringMaxLength * 3);
12+
} catch(e) {
13+
assert.equal(e.message, 'Invalid array buffer length');
14+
console.log(
15+
'1..0 # Skipped: intensive toString tests due to memory confinements');
16+
return;
17+
}
18+
19+
const buf = new Buffer(kStringMaxLength + 1);
20+
21+
assert.throws(function() {
22+
buf.toString('ascii');
23+
}, /toString failed/);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
6+
// v8 fails silently if string length > v8::String::kMaxLength
7+
// v8::String::kMaxLength defined in v8.h
8+
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
9+
10+
try {
11+
new Buffer(kStringMaxLength * 3);
12+
} catch(e) {
13+
assert.equal(e.message, 'Invalid array buffer length');
14+
console.log(
15+
'1..0 # Skipped: intensive toString tests due to memory confinements');
16+
return;
17+
}
18+
19+
const buf = new Buffer(kStringMaxLength + 1);
20+
21+
assert.throws(function() {
22+
buf.toString('base64');
23+
}, /toString failed/);

test/parallel/test-stringbytes-external-exceed-max-by-1.js test/parallel/test-stringbytes-external-exceed-max-by-1-binary.js

+5-26
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,16 @@ try {
1616
return;
1717
}
1818

19-
const buf1 = new Buffer(kStringMaxLength + 1);
19+
const buf = new Buffer(kStringMaxLength + 1);
2020

2121
assert.throws(function() {
22-
buf1.toString();
23-
}, /toString failed|Invalid array buffer length/);
24-
25-
assert.throws(function() {
26-
buf1.toString('ascii');
27-
}, /toString failed/);
28-
29-
assert.throws(function() {
30-
buf1.toString('utf8');
22+
buf.toString('binary');
3123
}, /toString failed/);
3224

33-
assert.throws(function() {
34-
buf1.toString('binary');
35-
}, /toString failed/);
36-
37-
assert.throws(function() {
38-
buf1.toString('base64');
39-
}, /toString failed/);
40-
41-
assert.throws(function() {
42-
buf1.toString('hex');
43-
}, /toString failed/);
44-
45-
var maxString = buf1.toString('binary', 1);
25+
var maxString = buf.toString('binary', 1);
4626
assert.equal(maxString.length, kStringMaxLength);
27+
// Free the memory early instead of at the end of the next assignment
4728
maxString = undefined;
4829

49-
maxString = buf1.toString('binary', 0, kStringMaxLength);
30+
maxString = buf.toString('binary', 0, kStringMaxLength);
5031
assert.equal(maxString.length, kStringMaxLength);
51-
// Free the memory early instead of at the end of the next assignment
52-
maxString = undefined;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
6+
// v8 fails silently if string length > v8::String::kMaxLength
7+
// v8::String::kMaxLength defined in v8.h
8+
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
9+
10+
try {
11+
new Buffer(kStringMaxLength * 3);
12+
} catch(e) {
13+
assert.equal(e.message, 'Invalid array buffer length');
14+
console.log(
15+
'1..0 # Skipped: intensive toString tests due to memory confinements');
16+
return;
17+
}
18+
19+
const buf = new Buffer(kStringMaxLength + 1);
20+
21+
assert.throws(function() {
22+
buf.toString('hex');
23+
}, /toString failed/);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
6+
// v8 fails silently if string length > v8::String::kMaxLength
7+
// v8::String::kMaxLength defined in v8.h
8+
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
9+
10+
try {
11+
new Buffer(kStringMaxLength * 3);
12+
} catch(e) {
13+
assert.equal(e.message, 'Invalid array buffer length');
14+
console.log(
15+
'1..0 # Skipped: intensive toString tests due to memory confinements');
16+
return;
17+
}
18+
19+
const buf = new Buffer(kStringMaxLength + 1);
20+
21+
assert.throws(function() {
22+
buf.toString();
23+
}, /toString failed|Invalid array buffer length/);
24+
25+
assert.throws(function() {
26+
buf.toString('utf8');
27+
}, /toString failed/);

0 commit comments

Comments
 (0)