From 540ec7ee561c77340a205a8b5f9a59f72f81452a Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Thu, 23 Jul 2020 11:29:00 -0700 Subject: [PATCH] fixup! testFinalizerException to gc until it throws --- .../test_exception/testFinalizerException.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/js-native-api/test_exception/testFinalizerException.js b/test/js-native-api/test_exception/testFinalizerException.js index d122e0c973b486..1ba74ba4802a0f 100644 --- a/test/js-native-api/test_exception/testFinalizerException.js +++ b/test/js-native-api/test_exception/testFinalizerException.js @@ -9,14 +9,24 @@ if (process.argv[2] === 'child') { } catch (anException) { anException.binding.createExternal(); } - const interval = setInterval(() => { - clearInterval(interval); - }, 100); + + // Collect garbage 10 times. At least one of those should throw the exception + // and cause the whole process to bail with it, its text printed to stderr and + // asserted by the parent process to match expectations. + let gcCount = 10; + (function gcLoop() { + global.gc(); + if (--gcCount > 0) { + setImmediate(() => gcLoop()); + } + })(); return; } const assert = require('assert'); const { spawnSync } = require('child_process'); -const child = spawnSync(process.execPath, [ __filename, 'child' ]); +const child = spawnSync(process.execPath, [ + '--expose-gc', __filename, 'child' +]); assert.strictEqual(child.signal, null); assert.match(child.stderr.toString(), /Error during Finalize/m);