mocha-distributed 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example/suite-7-duplicated-titles.js +25 -0
- package/index.js +23 -1
- package/package.json +1 -1
- package/test-example-nworkers.sh +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const util = require('./util.js');
|
|
2
|
+
const { expect } = require('chai');
|
|
3
|
+
|
|
4
|
+
// require('mocha-distributed')
|
|
5
|
+
require('../index.js');
|
|
6
|
+
|
|
7
|
+
describe ('suite-7', async function () {
|
|
8
|
+
this.timeout (10*1000);
|
|
9
|
+
this.retries(3);
|
|
10
|
+
|
|
11
|
+
// this test is created to make sure that
|
|
12
|
+
for (let i = 0; i < 10; i++) {
|
|
13
|
+
it ('test-7.1-duplicated-title', async function() {
|
|
14
|
+
const retryCount = this.test.currentRetry();
|
|
15
|
+
const id = `${i}`.padStart(2, '0');
|
|
16
|
+
console.log (`[id=${id}] test-7.1-duplicated-title (retry ${retryCount})`);
|
|
17
|
+
await util.sleep(0.1 + 0.5*Math.random());
|
|
18
|
+
|
|
19
|
+
// make this test flacky to make sure that it is retried
|
|
20
|
+
if (retryCount < 2) {
|
|
21
|
+
expect (false).to.be.true;
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
})
|
package/index.js
CHANGED
|
@@ -39,6 +39,11 @@ let g_capture = { stdout: null, stderr: null };
|
|
|
39
39
|
// EVENT_TEST_RETRY instead and never stores the error on the test object.
|
|
40
40
|
const g_retryErrors = new Map();
|
|
41
41
|
|
|
42
|
+
// Map to keep track of the number of times a test key full path has been seen,
|
|
43
|
+
// to add a suffix and parallelize duplicated test titles in multiple runners
|
|
44
|
+
const g_duplicateTestKeyFullPathCount = new Map();
|
|
45
|
+
let g_lastTestKeyFullPath = null;
|
|
46
|
+
|
|
42
47
|
// -----------------------------------------------------------------------------
|
|
43
48
|
// getTestPath
|
|
44
49
|
//
|
|
@@ -170,9 +175,26 @@ exports.mochaGlobalTeardown = async function () {
|
|
|
170
175
|
exports.mochaHooks = {
|
|
171
176
|
beforeEach: async function () {
|
|
172
177
|
const testPath = getTestPath(this.currentTest);
|
|
173
|
-
|
|
178
|
+
let testKeyFullPath = `${g_testExecutionId}:${getSerialGranularity(testPath.join(":"))}`;
|
|
174
179
|
const testKeySuite = `${g_testExecutionId}:${getSerialGranularity(testPath[0])}`;
|
|
175
180
|
|
|
181
|
+
// if this is the first attempt, we need to put a suffix to be able to
|
|
182
|
+
// parallelize duplicates in multiple runners
|
|
183
|
+
if ((this.currentTest._currentRetry || 0) === 0) {
|
|
184
|
+
g_duplicateTestKeyFullPathCount.set(
|
|
185
|
+
testKeyFullPath,
|
|
186
|
+
(g_duplicateTestKeyFullPathCount.get(testKeyFullPath) || 0) + 1
|
|
187
|
+
);
|
|
188
|
+
testKeyFullPath += `:dup-${g_duplicateTestKeyFullPathCount.get(testKeyFullPath)}`;
|
|
189
|
+
g_lastTestKeyFullPath = testKeyFullPath;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// ensure we use the same key for retries as the original attempt, otherwise
|
|
193
|
+
// we will screw up the distribution of tests; we use the last generated key
|
|
194
|
+
// since retries are executed sequentially
|
|
195
|
+
testKeyFullPath = g_lastTestKeyFullPath;
|
|
196
|
+
}
|
|
197
|
+
|
|
176
198
|
const testKey =
|
|
177
199
|
g_granularity === GRANULARITY.TEST ? testKeyFullPath : testKeySuite;
|
|
178
200
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mocha-distributed",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.8",
|
|
4
4
|
"description": "Run multiple mocha suites and tests in parallel, from different processes and different machines. Results available on a redis database.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
package/test-example-nworkers.sh
CHANGED
|
@@ -5,10 +5,10 @@ export MOCHA_DISTRIBUTED="redis://127.0.0.1"
|
|
|
5
5
|
npm install > /dev/null 2>&1
|
|
6
6
|
|
|
7
7
|
N=$1
|
|
8
|
-
COMMAND="mocha --require ./index.js example/**/*.js"
|
|
8
|
+
COMMAND="npx mocha --require ./index.js example/**/*.js"
|
|
9
9
|
|
|
10
10
|
# cleanup tmp files
|
|
11
|
-
rm tmp-*
|
|
11
|
+
rm -f tmp-*
|
|
12
12
|
|
|
13
13
|
echo "Spawning $N commands in parallel with Execution ID: $MOCHA_DISTRIBUTED_EXECUTION_ID"
|
|
14
14
|
|