test: migrate test.js to support concurrent test execution (#1531)
This patch migrates tests so that they can be run concurrently. - By default, tests still run in one thread. - To run tests in 4 parallel threads, run node test/test.js -j 4 or npm run unit -- -j 4 - Environment variable PPTR_PARALLEL_TESTS could be set to override default parallelization Every test gets passed in a state. State is set up in the beforeAll and beforeEach callbacks, and should be teared down in the afterAll and afterEach callbacks. By default, state has a parallelIndex variable initialized that defines the thread index that runs the execution.
This commit is contained in:
parent
4eaf52fa1d
commit
a5db6d412c
@ -67,7 +67,7 @@ const utils = module.exports = {
|
||||
*/
|
||||
dumpFrames: function(frame, indentation) {
|
||||
indentation = indentation || '';
|
||||
let result = indentation + frame.url();
|
||||
let result = indentation + frame.url().replace(/:\d{4}\//, ':<PORT>/');
|
||||
for (const child of frame.childFrames())
|
||||
result += '\n' + utils.dumpFrames(child, ' ' + indentation);
|
||||
return result;
|
||||
|
@ -1,5 +1,5 @@
|
||||
http://localhost:8907/frames/nested-frames.html
|
||||
http://localhost:8907/frames/two-frames.html
|
||||
http://localhost:8907/frames/frame.html
|
||||
http://localhost:8907/frames/frame.html
|
||||
http://localhost:8907/frames/frame.html
|
||||
http://localhost:<PORT>/frames/nested-frames.html
|
||||
http://localhost:<PORT>/frames/two-frames.html
|
||||
http://localhost:<PORT>/frames/frame.html
|
||||
http://localhost:<PORT>/frames/frame.html
|
||||
http://localhost:<PORT>/frames/frame.html
|
@ -1,5 +1,5 @@
|
||||
http://localhost:8907/frames/nested-frames.html
|
||||
http://localhost:8907/frames/two-frames.html
|
||||
http://localhost:8907/frames/frame.html
|
||||
http://localhost:8907/frames/frame.html
|
||||
http://localhost:8907/frames/frame.html
|
||||
http://localhost:<PORT>/frames/nested-frames.html
|
||||
http://localhost:<PORT>/frames/two-frames.html
|
||||
http://localhost:<PORT>/frames/frame.html
|
||||
http://localhost:<PORT>/frames/frame.html
|
||||
http://localhost:<PORT>/frames/frame.html
|
1740
test/test.js
1740
test/test.js
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
# TestRunner
|
||||
|
||||
- no additional binary required; tests are `node.js` scripts
|
||||
- testrunner is a library: no additional binary required; tests are `node.js` scripts
|
||||
- parallel wrt IO operations
|
||||
- supports async/await
|
||||
- modular
|
||||
@ -25,7 +25,7 @@ const {it, fit, xit} = runner;
|
||||
const {beforeAll, beforeEach, afterAll, afterEach} = runner;
|
||||
|
||||
beforeAll(state => {
|
||||
state.parallel; // this will be set with the execution thread id, either 0 or 1 in this example
|
||||
state.parallelIndex; // either 0 or 1 in this example, depending on the executing thread
|
||||
state.foo = 'bar'; // set state for every test
|
||||
});
|
||||
|
||||
|
@ -162,7 +162,7 @@ class TestPass {
|
||||
|
||||
const workerPromises = [];
|
||||
for (let i = 0; i < this._parallel; ++i)
|
||||
workerPromises.push(this._runSuite(i, [this._rootSuite], {parallel: i}));
|
||||
workerPromises.push(this._runSuite(i, [this._rootSuite], {parallelIndex: i}));
|
||||
await Promise.all(workerPromises);
|
||||
|
||||
for (const termination of terminations)
|
||||
|
Loading…
Reference in New Issue
Block a user