-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: skip instead of fail when mem constrained
The current implementation of tests for strings with length at or exceeding kStringMaxLength allocate a temporary buffer inside a try block to skip the test if there is insufficient memory. This commit adds an invocation of the garbage collector after the temporary buffer is allocated so that memory is freed for later allocations. Change the corresponding catch block to rethrow the original exception instead of asserting the exception message to provide more information about the exception. Add an additional check before trying to allocate memory to immediately skip the test on machines with insufficient total memory. PR-URL: #3697 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
- Loading branch information
1 parent
b619831
commit a40b9ca
Showing
9 changed files
with
140 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
'use strict'; | ||
// Flags: --expose-gc | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
// v8 fails silently if string length > v8::String::kMaxLength | ||
// v8::String::kMaxLength defined in v8.h | ||
const kStringMaxLength = process.binding('buffer').kStringMaxLength; | ||
|
||
const skipMessage = | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'; | ||
if (!common.enoughTestMem) { | ||
console.log(skipMessage); | ||
return; | ||
} | ||
assert(typeof gc === 'function', 'Run this test with --expose-gc'); | ||
|
||
try { | ||
new Buffer(kStringMaxLength * 3); | ||
var buf = new Buffer(kStringMaxLength); | ||
// Try to allocate memory first then force gc so future allocations succeed. | ||
new Buffer(2 * kStringMaxLength); | ||
gc(); | ||
} catch(e) { | ||
assert.equal(e.message, 'Invalid array buffer length'); | ||
console.log( | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'); | ||
// If the exception is not due to memory confinement then rethrow it. | ||
if (e.message !== 'Invalid array buffer length') throw (e); | ||
console.log(skipMessage); | ||
return; | ||
} | ||
|
||
const buf = new Buffer(kStringMaxLength); | ||
|
||
const maxString = buf.toString('binary'); | ||
assert.equal(maxString.length, kStringMaxLength); |
24 changes: 17 additions & 7 deletions
24
test/parallel/test-stringbytes-external-exceed-max-by-1-ascii.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
'use strict'; | ||
// Flags: --expose-gc | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const skipMessage = | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'; | ||
if (!common.enoughTestMem) { | ||
console.log(skipMessage); | ||
return; | ||
} | ||
assert(typeof gc === 'function', 'Run this test with --expose-gc'); | ||
|
||
// v8 fails silently if string length > v8::String::kMaxLength | ||
// v8::String::kMaxLength defined in v8.h | ||
const kStringMaxLength = process.binding('buffer').kStringMaxLength; | ||
|
||
try { | ||
new Buffer(kStringMaxLength * 3); | ||
var buf = new Buffer(kStringMaxLength + 1); | ||
// Try to allocate memory first then force gc so future allocations succeed. | ||
new Buffer(2 * kStringMaxLength); | ||
gc(); | ||
} catch(e) { | ||
assert.equal(e.message, 'Invalid array buffer length'); | ||
console.log( | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'); | ||
// If the exception is not due to memory confinement then rethrow it. | ||
if (e.message !== 'Invalid array buffer length') throw (e); | ||
console.log(skipMessage); | ||
return; | ||
} | ||
|
||
const buf = new Buffer(kStringMaxLength + 1); | ||
|
||
assert.throws(function() { | ||
buf.toString('ascii'); | ||
}, /"toString\(\)" failed/); |
24 changes: 17 additions & 7 deletions
24
test/parallel/test-stringbytes-external-exceed-max-by-1-base64.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
'use strict'; | ||
// Flags: --expose-gc | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const skipMessage = | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'; | ||
if (!common.enoughTestMem) { | ||
console.log(skipMessage); | ||
return; | ||
} | ||
assert(typeof gc === 'function', 'Run this test with --expose-gc'); | ||
|
||
// v8 fails silently if string length > v8::String::kMaxLength | ||
// v8::String::kMaxLength defined in v8.h | ||
const kStringMaxLength = process.binding('buffer').kStringMaxLength; | ||
|
||
try { | ||
new Buffer(kStringMaxLength * 3); | ||
var buf = new Buffer(kStringMaxLength + 1); | ||
// Try to allocate memory first then force gc so future allocations succeed. | ||
new Buffer(2 * kStringMaxLength); | ||
gc(); | ||
} catch(e) { | ||
assert.equal(e.message, 'Invalid array buffer length'); | ||
console.log( | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'); | ||
// If the exception is not due to memory confinement then rethrow it. | ||
if (e.message !== 'Invalid array buffer length') throw (e); | ||
console.log(skipMessage); | ||
return; | ||
} | ||
|
||
const buf = new Buffer(kStringMaxLength + 1); | ||
|
||
assert.throws(function() { | ||
buf.toString('base64'); | ||
}, /"toString\(\)" failed/); |
24 changes: 17 additions & 7 deletions
24
test/parallel/test-stringbytes-external-exceed-max-by-1-binary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 17 additions & 7 deletions
24
test/parallel/test-stringbytes-external-exceed-max-by-1-hex.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
'use strict'; | ||
// Flags: --expose-gc | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const skipMessage = | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'; | ||
if (!common.enoughTestMem) { | ||
console.log(skipMessage); | ||
return; | ||
} | ||
assert(typeof gc === 'function', 'Run this test with --expose-gc'); | ||
|
||
// v8 fails silently if string length > v8::String::kMaxLength | ||
// v8::String::kMaxLength defined in v8.h | ||
const kStringMaxLength = process.binding('buffer').kStringMaxLength; | ||
|
||
try { | ||
new Buffer(kStringMaxLength * 3); | ||
var buf = new Buffer(kStringMaxLength + 1); | ||
// Try to allocate memory first then force gc so future allocations succeed. | ||
new Buffer(2 * kStringMaxLength); | ||
gc(); | ||
} catch(e) { | ||
assert.equal(e.message, 'Invalid array buffer length'); | ||
console.log( | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'); | ||
// If the exception is not due to memory confinement then rethrow it. | ||
if (e.message !== 'Invalid array buffer length') throw (e); | ||
console.log(skipMessage); | ||
return; | ||
} | ||
|
||
const buf = new Buffer(kStringMaxLength + 1); | ||
|
||
assert.throws(function() { | ||
buf.toString('hex'); | ||
}, /"toString\(\)" failed/); |
24 changes: 17 additions & 7 deletions
24
test/parallel/test-stringbytes-external-exceed-max-by-1-utf8.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 18 additions & 8 deletions
26
test/parallel/test-stringbytes-external-exceed-max-by-2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
'use strict'; | ||
// Flags: --expose-gc | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const skipMessage = | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'; | ||
if (!common.enoughTestMem) { | ||
console.log(skipMessage); | ||
return; | ||
} | ||
assert(typeof gc === 'function', 'Run this test with --expose-gc'); | ||
|
||
// v8 fails silently if string length > v8::String::kMaxLength | ||
// v8::String::kMaxLength defined in v8.h | ||
const kStringMaxLength = process.binding('buffer').kStringMaxLength; | ||
|
||
try { | ||
new Buffer(kStringMaxLength * 3); | ||
var buf = new Buffer(kStringMaxLength + 2); | ||
// Try to allocate memory first then force gc so future allocations succeed. | ||
new Buffer(2 * kStringMaxLength); | ||
gc(); | ||
} catch(e) { | ||
assert.equal(e.message, 'Invalid array buffer length'); | ||
console.log( | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'); | ||
// If the exception is not due to memory confinement then rethrow it. | ||
if (e.message !== 'Invalid array buffer length') throw (e); | ||
console.log(skipMessage); | ||
return; | ||
} | ||
|
||
const buf2 = new Buffer(kStringMaxLength + 2); | ||
|
||
const maxString = buf2.toString('utf16le'); | ||
const maxString = buf.toString('utf16le'); | ||
assert.equal(maxString.length, (kStringMaxLength + 2) / 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
'use strict'; | ||
// Flags: --expose-gc | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const skipMessage = | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'; | ||
if (!common.enoughTestMem) { | ||
console.log(skipMessage); | ||
return; | ||
} | ||
assert(typeof gc === 'function', 'Run this test with --expose-gc'); | ||
|
||
// v8 fails silently if string length > v8::String::kMaxLength | ||
// v8::String::kMaxLength defined in v8.h | ||
const kStringMaxLength = process.binding('buffer').kStringMaxLength; | ||
|
||
try { | ||
new Buffer(kStringMaxLength * 3); | ||
var buf = new Buffer(kStringMaxLength * 2 + 2); | ||
// Try to allocate memory first then force gc so future allocations succeed. | ||
new Buffer(2 * kStringMaxLength); | ||
gc(); | ||
} catch(e) { | ||
assert.equal(e.message, 'Invalid array buffer length'); | ||
console.log( | ||
'1..0 # Skipped: intensive toString tests due to memory confinements'); | ||
// If the exception is not due to memory confinement then rethrow it. | ||
if (e.message !== 'Invalid array buffer length') throw (e); | ||
console.log(skipMessage); | ||
return; | ||
} | ||
|
||
const buf0 = new Buffer(kStringMaxLength * 2 + 2); | ||
|
||
assert.throws(function() { | ||
buf0.toString('utf16le'); | ||
buf.toString('utf16le'); | ||
}, /"toString\(\)" failed/); |