From 31c971d64114af02125e9af8e4f034bfce4eb685 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 8 Oct 2015 13:56:34 -0700 Subject: [PATCH] test: parallelize long-running test Fixes a persistently troublesome failing test by splitting it out into multiple parallel tests. Reviewed By: Evan Lucas Reviewed By: Trevor Norris Reviewed By: James M Snell PR-URL: https://github.com/nodejs/node/pull/3287 --- .../test-stringbytes-external-at-max.js | 22 ++++++ ...st-stringbytes-external-exceed-max-by-1.js | 52 ++++++++++++++ ...st-stringbytes-external-exceed-max-by-2.js | 22 ++++++ .../test-stringbytes-external-exceed-max.js | 23 +++++++ test/parallel/test-stringbytes-external.js | 69 ------------------- 5 files changed, 119 insertions(+), 69 deletions(-) create mode 100644 test/parallel/test-stringbytes-external-at-max.js create mode 100644 test/parallel/test-stringbytes-external-exceed-max-by-1.js create mode 100644 test/parallel/test-stringbytes-external-exceed-max-by-2.js create mode 100644 test/parallel/test-stringbytes-external-exceed-max.js diff --git a/test/parallel/test-stringbytes-external-at-max.js b/test/parallel/test-stringbytes-external-at-max.js new file mode 100644 index 00000000000000..6678e5355224b3 --- /dev/null +++ b/test/parallel/test-stringbytes-external-at-max.js @@ -0,0 +1,22 @@ +'use strict'; + +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; + +try { + new Buffer(kStringMaxLength * 3); +} catch(e) { + assert.equal(e.message, 'Invalid array buffer length'); + console.log( + '1..0 # Skipped: intensive toString tests due to memory confinements'); + return; +} + +const buf = new Buffer(kStringMaxLength); + +const maxString = buf.toString('binary'); +assert.equal(maxString.length, kStringMaxLength); diff --git a/test/parallel/test-stringbytes-external-exceed-max-by-1.js b/test/parallel/test-stringbytes-external-exceed-max-by-1.js new file mode 100644 index 00000000000000..8e2a5bf01f2596 --- /dev/null +++ b/test/parallel/test-stringbytes-external-exceed-max-by-1.js @@ -0,0 +1,52 @@ +'use strict'; + +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; + +try { + new Buffer(kStringMaxLength * 3); +} catch(e) { + assert.equal(e.message, 'Invalid array buffer length'); + console.log( + '1..0 # Skipped: intensive toString tests due to memory confinements'); + return; +} + +const buf1 = new Buffer(kStringMaxLength + 1); + +assert.throws(function() { + buf1.toString(); +}, /toString failed|Invalid array buffer length/); + +assert.throws(function() { + buf1.toString('ascii'); +}, /toString failed/); + +assert.throws(function() { + buf1.toString('utf8'); +}, /toString failed/); + +assert.throws(function() { + buf1.toString('binary'); +}, /toString failed/); + +assert.throws(function() { + buf1.toString('base64'); +}, /toString failed/); + +assert.throws(function() { + buf1.toString('hex'); +}, /toString failed/); + +var maxString = buf1.toString('binary', 1); +assert.equal(maxString.length, kStringMaxLength); +maxString = undefined; + +maxString = buf1.toString('binary', 0, kStringMaxLength); +assert.equal(maxString.length, kStringMaxLength); +// Free the memory early instead of at the end of the next assignment +maxString = undefined; diff --git a/test/parallel/test-stringbytes-external-exceed-max-by-2.js b/test/parallel/test-stringbytes-external-exceed-max-by-2.js new file mode 100644 index 00000000000000..879e4ae91dfb60 --- /dev/null +++ b/test/parallel/test-stringbytes-external-exceed-max-by-2.js @@ -0,0 +1,22 @@ +'use strict'; + +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; + +try { + new Buffer(kStringMaxLength * 3); +} catch(e) { + assert.equal(e.message, 'Invalid array buffer length'); + console.log( + '1..0 # Skipped: intensive toString tests due to memory confinements'); + return; +} + +const buf2 = new Buffer(kStringMaxLength + 2); + +const maxString = buf2.toString('utf16le'); +assert.equal(maxString.length, (kStringMaxLength + 2) / 2); diff --git a/test/parallel/test-stringbytes-external-exceed-max.js b/test/parallel/test-stringbytes-external-exceed-max.js new file mode 100644 index 00000000000000..0a6f585b66f3ad --- /dev/null +++ b/test/parallel/test-stringbytes-external-exceed-max.js @@ -0,0 +1,23 @@ +'use strict'; + +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; + +try { + new Buffer(kStringMaxLength * 3); +} catch(e) { + assert.equal(e.message, 'Invalid array buffer length'); + console.log( + '1..0 # Skipped: intensive toString tests due to memory confinements'); + return; +} + +const buf0 = new Buffer(kStringMaxLength * 2 + 2); + +assert.throws(function() { + buf0.toString('utf16le'); +}, /toString failed/); diff --git a/test/parallel/test-stringbytes-external.js b/test/parallel/test-stringbytes-external.js index ddbbcd599fa4da..ba3f0c5d1d9ade 100644 --- a/test/parallel/test-stringbytes-external.js +++ b/test/parallel/test-stringbytes-external.js @@ -107,72 +107,3 @@ var PRE_3OF4_APEX = Math.ceil((EXTERN_APEX / 4) * 3) - RADIOS; assert.equal(a, b); assert.equal(b, c); })(); - -// v8 fails silently if string length > v8::String::kMaxLength -(function() { - // v8::String::kMaxLength defined in v8.h - const kStringMaxLength = process.binding('buffer').kStringMaxLength; - - try { - new Buffer(kStringMaxLength * 3); - } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); - return; - } - - const buf0 = new Buffer(kStringMaxLength * 2 + 2); - const buf1 = buf0.slice(0, kStringMaxLength + 1); - const buf2 = buf0.slice(0, kStringMaxLength); - const buf3 = buf0.slice(0, kStringMaxLength + 2); - - assert.throws(function() { - buf1.toString(); - }, /toString failed|Invalid array buffer length/); - - assert.throws(function() { - buf1.toString('ascii'); - }, /toString failed/); - - assert.throws(function() { - buf1.toString('utf8'); - }, /toString failed/); - - assert.throws(function() { - buf0.toString('utf16le'); - }, /toString failed/); - - assert.throws(function() { - buf1.toString('binary'); - }, /toString failed/); - - assert.throws(function() { - buf1.toString('base64'); - }, /toString failed/); - - assert.throws(function() { - buf1.toString('hex'); - }, /toString failed/); - - var maxString = buf2.toString(); - assert.equal(maxString.length, kStringMaxLength); - // Free the memory early instead of at the end of the next assignment - maxString = undefined; - - maxString = buf2.toString('binary'); - assert.equal(maxString.length, kStringMaxLength); - maxString = undefined; - - maxString = buf1.toString('binary', 1); - assert.equal(maxString.length, kStringMaxLength); - maxString = undefined; - - maxString = buf1.toString('binary', 0, kStringMaxLength); - assert.equal(maxString.length, kStringMaxLength); - maxString = undefined; - - maxString = buf3.toString('utf16le'); - assert.equal(maxString.length, (kStringMaxLength + 2) / 2); - maxString = undefined; -})();