Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
test: fix another flaky stringbytes test
Avoid depending on precise timing of when an object will be collected
by GC. This test was missed by #6039 as it happened to be in a
different directory than the rest.

Ref: #6039
PR-URL: #6073
Reviewed-By: Trott - Rich Trott <rtrott@gmail.com>
  • Loading branch information
ofrobots committed Apr 6, 2016
commit b73e1b3c5af7675cb1fcf754bc574d803df2332d
4 changes: 3 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Tests for when the `--abort-on-uncaught-exception` flag is used.

### addons

Tests for [addon](https://nodejs.org/api/addons.html) functionality.
Tests for [addon](https://nodejs.org/api/addons.html) functionality along with
some tests that require an addon to function properly.


| Runs on CI |
|:----------:|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
// Flags: --expose-gc

const common = require('../common');
const common = require('../../common');
const binding = require('./build/Release/binding');
const assert = require('assert');

// v8 fails silently if string length > v8::String::kMaxLength
Expand All @@ -14,19 +14,21 @@ if (!common.enoughTestMem) {
console.log(skipMessage);
return;
}
assert(typeof gc === 'function', 'Run this test with --expose-gc');

try {
var buf = Buffer.allocUnsafe(kStringMaxLength);
// Try to allocate memory first then force gc so future allocations succeed.
Buffer.allocUnsafe(2 * kStringMaxLength);
gc();
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
console.log(skipMessage);
return;
}

// Ensure we have enough memory available for future allocations to succeed.
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
console.log(skipMessage);
return;
}

const maxString = buf.toString('binary');
assert.equal(maxString.length, kStringMaxLength);