forked from nodejs/node-addon-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make tests work on all Node versions
- Make GC tests (arraybuffer, buffer, external) async, to account for different GC behavior with different versions of V8 and ChakraCore, similar to nodejs/node#13121 - In test/index.js, use the --napi-modules and --expose-gc command-line flags automatically
- Loading branch information
Showing
9 changed files
with
198 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
'use strict'; | ||
|
||
if (typeof global.gc !== 'function') { | ||
throw new Error('Tests require --expose-gc flag.') | ||
} | ||
|
||
let testModules = [ | ||
'arraybuffer', | ||
'asyncworker', | ||
'buffer', | ||
'error', | ||
'external', | ||
'function', | ||
'name', | ||
'arraybuffer', | ||
'asyncworker', | ||
'buffer', | ||
'error', | ||
'external', | ||
'function', | ||
'name', | ||
]; | ||
|
||
testModules.forEach(name => { | ||
try { | ||
require('./' + name); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
if (typeof global.gc === 'function') { | ||
// Requiring each module runs tests in the module. | ||
testModules.forEach(name => { | ||
require('./' + name); | ||
}); | ||
} else { | ||
// Make it easier to run with the correct (version-dependent) command-line args. | ||
const args = [ '--expose-gc', __filename ]; | ||
if (require('../index').isNodeApiBuiltin) { | ||
args.splice(0, 0, '--napi-modules'); | ||
} | ||
const child = require('child_process').spawnSync(process.argv[0], args, { | ||
stdio: 'inherit', | ||
}); | ||
process.exitCode = child.status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Run each test function in sequence, | ||
// with an async delay and GC call between each. | ||
function runGCTests(tests, i, title) { | ||
if (!i) { | ||
i = 0; | ||
} | ||
|
||
if (tests[i]) { | ||
if (typeof tests[i] === 'string') { | ||
title = tests[i]; | ||
runGCTests(tests, i + 1, title); | ||
} else { | ||
try { | ||
tests[i](); | ||
} catch (e) { | ||
console.error('Test failed: ' + title); | ||
throw e; | ||
} | ||
setImmediate(() => { | ||
global.gc(); | ||
runGCTests(tests, i + 1, title); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
runGCTests, | ||
}; |