-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: run interfering tests in their own process
Tests such as addon and addon_data both use SetInstanceData. Thus, they overwrite each other's instance data. We change them both to run in a child process such that they do not call SetInstanceData on init, but rather they return a JS function on init which, when called, produces the actual binding which needs SetInstanceData. We also introduce a utility function for launching a snippet of code in its own child process for the purpose of running such tests that interfere with each other.
- Loading branch information
1 parent
665f4aa
commit b63f9e7
Showing
11 changed files
with
164 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
||
module.exports = require('./common').runTest(test); | ||
|
||
function test (binding) { | ||
assert.strictEqual(binding.addon.increment(), 43); | ||
assert.strictEqual(binding.addon.increment(), 44); | ||
assert.strictEqual(binding.addon.subObject.decrement(), 43); | ||
} | ||
module.exports = require('./common').runTestInChildProcess({ | ||
suite: 'addon', | ||
testName: 'workingCode', | ||
expectedStderr: ['TestAddon::~TestAddon'] | ||
}); |
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,46 +1,24 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const { spawn } = require('child_process'); | ||
const readline = require('readline'); | ||
const common = require('./common'); | ||
|
||
module.exports = require('./common').runTestWithBindingPath(test); | ||
module.exports = common.runTest(test); | ||
|
||
// Make sure the instance data finalizer is called at process exit. If the hint | ||
// is non-zero, it will be printed out by the child process. | ||
function testFinalizer (bindingName, hint, expected) { | ||
return new Promise((resolve) => { | ||
bindingName = bindingName.split('\\').join('\\\\'); | ||
const child = spawn(process.execPath, [ | ||
'-e', | ||
`require('${bindingName}').addon_data(${hint}).verbose = true;` | ||
]); | ||
const actual = []; | ||
readline | ||
.createInterface({ input: child.stderr }) | ||
.on('line', (line) => { | ||
if (expected.indexOf(line) >= 0) { | ||
actual.push(line); | ||
} | ||
}) | ||
.on('close', () => { | ||
assert.deepStrictEqual(expected, actual); | ||
resolve(); | ||
}); | ||
async function test () { | ||
await common.runTestInChildProcess({ | ||
suite: 'addon_data', | ||
testName: 'workingCode' | ||
}); | ||
} | ||
|
||
async function test (bindingName) { | ||
const binding = require(bindingName).addon_data(0); | ||
|
||
// Make sure it is possible to get/set instance data. | ||
assert.strictEqual(binding.verbose.verbose, false); | ||
binding.verbose = true; | ||
assert.strictEqual(binding.verbose.verbose, true); | ||
binding.verbose = false; | ||
assert.strictEqual(binding.verbose.verbose, false); | ||
await common.runTestInChildProcess({ | ||
suite: 'addon_data', | ||
testName: 'cleanupWithoutHint', | ||
expectedStderr: ['addon_data: Addon::~Addon'] | ||
}); | ||
|
||
await testFinalizer(bindingName, 0, ['addon_data: Addon::~Addon']); | ||
await testFinalizer(bindingName, 42, | ||
['addon_data: Addon::~Addon', 'hint: 42']); | ||
await common.runTestInChildProcess({ | ||
suite: 'addon_data', | ||
testName: 'cleanupWithHint', | ||
expectedStderr: ['addon_data: Addon::~Addon', 'hint: 42'] | ||
}); | ||
} |
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,11 @@ | ||
'use strict'; | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
workingCode: binding => { | ||
const addon = binding.addon(); | ||
assert.strictEqual(addon.increment(), 43); | ||
assert.strictEqual(addon.increment(), 44); | ||
assert.strictEqual(addon.subObject.decrement(), 43); | ||
} | ||
}; |
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,24 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
||
// Make sure the instance data finalizer is called at process exit. If the hint | ||
// is non-zero, it will be printed out by the child process. | ||
const cleanupTest = (binding, hint) => { | ||
binding.addon_data(hint).verbose = true; | ||
}; | ||
|
||
module.exports = { | ||
workingCode: binding => { | ||
const addonData = binding.addon_data(0); | ||
|
||
// Make sure it is possible to get/set instance data. | ||
assert.strictEqual(addonData.verbose.verbose, false); | ||
addonData.verbose = true; | ||
assert.strictEqual(addonData.verbose.verbose, true); | ||
addonData.verbose = false; | ||
assert.strictEqual(addonData.verbose.verbose, false); | ||
}, | ||
cleanupWithHint: binding => cleanupTest(binding, 42), | ||
cleanupWithoutHint: binding => cleanupTest(binding, 0) | ||
}; |
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,22 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const testUtil = require('../testUtil'); | ||
|
||
module.exports = { | ||
runTest: function (binding) { | ||
return testUtil.runGCTests([ | ||
'objectwrap function', | ||
() => { | ||
const { FunctionTest } = binding.objectwrap_function(); | ||
const newConstructed = new FunctionTest(); | ||
const functionConstructed = FunctionTest(); | ||
assert(newConstructed instanceof FunctionTest); | ||
assert(functionConstructed instanceof FunctionTest); | ||
assert.throws(() => (FunctionTest(true)), /an exception/); | ||
}, | ||
// Do one gc before returning. | ||
() => {} | ||
]); | ||
} | ||
}; |
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,22 +1,6 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const testUtil = require('./testUtil'); | ||
|
||
function test (binding) { | ||
return testUtil.runGCTests([ | ||
'objectwrap function', | ||
() => { | ||
const { FunctionTest } = binding.objectwrap_function; | ||
const newConstructed = new FunctionTest(); | ||
const functionConstructed = FunctionTest(); | ||
assert(newConstructed instanceof FunctionTest); | ||
assert(functionConstructed instanceof FunctionTest); | ||
assert.throws(() => (FunctionTest(true)), /an exception/); | ||
}, | ||
// Do on gc before returning. | ||
() => {} | ||
]); | ||
} | ||
|
||
module.exports = require('./common').runTest(test); | ||
module.exports = require('./common').runTestInChildProcess({ | ||
suite: 'objectwrap_function', | ||
testName: 'runTest' | ||
}); |