Skip to content

Commit b73e1b3

Browse files
committed
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 nodejs#6039 as it happened to be in a different directory than the rest. Ref: nodejs#6039 PR-URL: nodejs#6073 Reviewed-By: Trott - Rich Trott <rtrott@gmail.com>
1 parent 82d57d3 commit b73e1b3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

test/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Tests for when the `--abort-on-uncaught-exception` flag is used.
1010

1111
### addons
1212

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

1517
| Runs on CI |
1618
|:----------:|
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
2-
// Flags: --expose-gc
32

4-
const common = require('../common');
3+
const common = require('../../common');
4+
const binding = require('./build/Release/binding');
55
const assert = require('assert');
66

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

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

27+
// Ensure we have enough memory available for future allocations to succeed.
28+
if (!binding.ensureAllocation(2 * kStringMaxLength)) {
29+
console.log(skipMessage);
30+
return;
31+
}
32+
3133
const maxString = buf.toString('binary');
3234
assert.equal(maxString.length, kStringMaxLength);

0 commit comments

Comments
 (0)