Skip to content

Commit beccf21

Browse files
committed
test: fix up delays for array buffer test
Signed-off-by: Michael Dawson <[email protected]> PR-URL: #737 Refs: #735 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 45cb1d9 commit beccf21

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

test/arraybuffer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ function test(binding) {
3939
},
4040
() => {
4141
global.gc();
42+
},
43+
() => {
4244
assert.strictEqual(1, binding.arraybuffer.getFinalizeCount());
4345
},
4446

@@ -51,6 +53,8 @@ function test(binding) {
5153
},
5254
() => {
5355
global.gc();
56+
},
57+
() => {
5458
assert.strictEqual(1, binding.arraybuffer.getFinalizeCount());
5559
},
5660

test/buffer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function test(binding) {
4848
},
4949
() => {
5050
global.gc();
51+
},
52+
() => {
5153
assert.strictEqual(1, binding.buffer.getFinalizeCount());
5254
},
5355

@@ -60,6 +62,8 @@ function test(binding) {
6062
},
6163
() => {
6264
global.gc();
65+
},
66+
() => {
6367
assert.strictEqual(1, binding.buffer.getFinalizeCount());
6468
},
6569
]);

test/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ let testModules = [
5858
];
5959

6060
const napiVersion = Number(process.versions.napi)
61+
const majorNodeVersion = process.versions.node.split('.')[0]
6162

6263
if (napiVersion < 3) {
6364
testModules.splice(testModules.indexOf('callbackscope'), 1);
@@ -98,8 +99,14 @@ if (typeof global.gc === 'function') {
9899

99100
console.log('\nAll tests passed!');
100101
} else {
101-
// Make it easier to run with the correct (version-dependent) command-line args.
102-
const child = require('./napi_child').spawnSync(process.argv[0], [ '--expose-gc', __filename ], {
102+
// Construct the correct (version-dependent) command-line args.
103+
let args = ['--expose-gc', '--no-concurrent-array-buffer-freeing'];
104+
if (majorNodeVersion >= 14) {
105+
args.push('--no-concurrent-array-buffer-sweeping');
106+
}
107+
args.push(__filename);
108+
109+
const child = require('./napi_child').spawnSync(process.argv[0], args, {
103110
stdio: 'inherit',
104111
});
105112

test/testUtil.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
// Run each test function in sequence,
22
// with an async delay and GC call between each.
3+
4+
function tick(x, cb) {
5+
function ontick() {
6+
if (--x === 0) {
7+
if (typeof cb === 'function') cb();
8+
} else {
9+
setImmediate(ontick);
10+
}
11+
}
12+
setImmediate(ontick);
13+
};
14+
315
function runGCTests(tests, i, title) {
416
if (!i) {
517
i = 0;
@@ -18,7 +30,7 @@ function runGCTests(tests, i, title) {
1830
}
1931
setImmediate(() => {
2032
global.gc();
21-
runGCTests(tests, i + 1, title);
33+
tick(10, runGCTests(tests, i + 1, title));
2234
});
2335
}
2436
}

0 commit comments

Comments
 (0)