mocha-distributed 0.9.8 → 0.9.10
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/README.md +22 -10
- package/index.js +26 -16
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -34,20 +34,20 @@ is:
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
Make sure you have a redis running somewhere with IP visibility from the machine
|
|
37
|
-
or machines where you want to run the tests on.
|
|
37
|
+
or machines where you want to run the tests on.
|
|
38
38
|
|
|
39
39
|
Finally, on each of the runners just run:
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
42
|
$ export MOCHA_DISTRIBUTED_EXECUTION_ID="execution__2024-01-01__20:10"
|
|
43
|
-
$ export MOCHA_DISTRIBUTED="redis://redis.address"
|
|
43
|
+
$ export MOCHA_DISTRIBUTED="redis://redis.address"
|
|
44
44
|
$ mocha --require mocha-distributed test/**/*.js
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
There are several environment variables that allow you to control the behaviour
|
|
48
48
|
of distributed tests, but this is the simplest way to launch them.
|
|
49
49
|
|
|
50
|
-
MOCHA_DISTRIBUTED is the one holding the redis address, this is the only
|
|
50
|
+
MOCHA_DISTRIBUTED is the one holding the redis address, this is the only
|
|
51
51
|
requirement to make mocha-distributed work.
|
|
52
52
|
|
|
53
53
|
MOCHA_DISTRIBUTED_EXECUTION_ID is the other variable you want to pay attention
|
|
@@ -62,7 +62,7 @@ whether a test has already been executed or not by other of their peers.
|
|
|
62
62
|
Right now this variable is the one used to specify the node that will hold
|
|
63
63
|
information about tests being run. This project only supports redis right
|
|
64
64
|
now. This variable can take the form:
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
redis[s]://[[username][:password]@][host][:port]
|
|
67
67
|
|
|
68
68
|
Please make sure it has visibility to the desired redis server.
|
|
@@ -81,11 +81,11 @@ whether a test has already been executed or not by other of their peers.
|
|
|
81
81
|
Reusing this variable in different executions will cause your tests to be
|
|
82
82
|
skipped.
|
|
83
83
|
|
|
84
|
-
Use a random uuid or other random value, a kubernetes job_name, your
|
|
84
|
+
Use a random uuid or other random value, a kubernetes job_name, your
|
|
85
85
|
build system job id, ...
|
|
86
86
|
|
|
87
87
|
- **MOCHA_DISTRIBUTED_GRANULARITY** = test
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
- test (default)
|
|
90
90
|
Potentially all tests can be executed by any runner in any order. This
|
|
91
91
|
is the default, but if you have trouble running your tests in parallel
|
|
@@ -105,7 +105,7 @@ whether a test has already been executed or not by other of their peers.
|
|
|
105
105
|
|
|
106
106
|
- **MOCHA_DISTRIBUTED_EXPIRATION_TIME** = 604800
|
|
107
107
|
|
|
108
|
-
Configures to how long the data is kept in redis before it expires (in
|
|
108
|
+
Configures to how long the data is kept in redis before it expires (in
|
|
109
109
|
seconds). 7 days is the default. The amount of data in redis is minimal,
|
|
110
110
|
so you probably don't want to play with it.
|
|
111
111
|
|
|
@@ -126,7 +126,7 @@ whether a test has already been executed or not by other of their peers.
|
|
|
126
126
|
|
|
127
127
|
All runners write the test result in JSON format in a specific redis list.
|
|
128
128
|
|
|
129
|
-
The list is basically the execution ID from the variable
|
|
129
|
+
The list is basically the execution ID from the variable
|
|
130
130
|
MOCHA_DISTRIBUTED_EXECUTION_ID concatenated to ':test_result'
|
|
131
131
|
|
|
132
132
|
For example, if you are using: MOCHA_DISTRIBUTED_EXECUTION_ID="abcdefg"
|
|
@@ -272,7 +272,7 @@ Run as many processes as you'd like.
|
|
|
272
272
|
|
|
273
273
|
### Using kubernetes parallel jobs to launch tests
|
|
274
274
|
|
|
275
|
-
If you plan to use kubernetes to launch parallel jobs, make sure the backoff
|
|
275
|
+
If you plan to use kubernetes to launch parallel jobs, make sure the backoff
|
|
276
276
|
limit is set to 1, so it does not retry the job after it fails, and make sure
|
|
277
277
|
you set execution ID to a different value each time (but common across all
|
|
278
278
|
parallel executions).
|
|
@@ -317,12 +317,24 @@ If you use jenkins, bamboo or any other build system, make sure
|
|
|
317
317
|
one redis is installed somewhere and all runners can access to it.
|
|
318
318
|
|
|
319
319
|
Create as many processes, nodes, dockers, kubernetes pods as you wish,
|
|
320
|
-
but for each of the runners that you create, make sure each of them can connect
|
|
320
|
+
but for each of the runners that you create, make sure each of them can connect
|
|
321
321
|
to the redis instance (e.g are in the same network).
|
|
322
322
|
|
|
323
323
|
You can use the project name and build ID or job id as the execution ID for
|
|
324
324
|
mocha-distributed. Use something unique among the builds of all your projects.
|
|
325
325
|
|
|
326
|
+
## Testing mocha-distributed itself
|
|
327
|
+
|
|
328
|
+
Run the following commands:
|
|
329
|
+
|
|
330
|
+
```
|
|
331
|
+
$ docker compose up -d
|
|
332
|
+
$ ./test-example-nworkers.sh 3
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Validate that tmp-output-*.log have executed properly. Pay special attention to
|
|
336
|
+
serial behaviour on the different files/workers and tests with duplicate keys.
|
|
337
|
+
|
|
326
338
|
## MIT License
|
|
327
339
|
|
|
328
340
|
Copyright (c) 2018 Pau Sanchez
|
package/index.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
const redis = require("redis");
|
|
7
7
|
const crypto = require("crypto");
|
|
8
8
|
|
|
9
|
+
const SERIAL_PREFIX = "[serial";
|
|
10
|
+
|
|
9
11
|
const GRANULARITY = {
|
|
10
12
|
TEST: "test",
|
|
11
13
|
SUITE: "suite",
|
|
@@ -81,7 +83,7 @@ function getTestPath(testContext) {
|
|
|
81
83
|
function getSerialGranularity(testKey) {
|
|
82
84
|
// NOTE: a regular expression might be trickier to get right, since you can
|
|
83
85
|
// have multiple instances of [serialxxxx] on the same string
|
|
84
|
-
let index = testKey.indexOf(
|
|
86
|
+
let index = testKey.indexOf(SERIAL_PREFIX)
|
|
85
87
|
if (index === -1)
|
|
86
88
|
return testKey
|
|
87
89
|
|
|
@@ -178,21 +180,29 @@ exports.mochaHooks = {
|
|
|
178
180
|
let testKeyFullPath = `${g_testExecutionId}:${getSerialGranularity(testPath.join(":"))}`;
|
|
179
181
|
const testKeySuite = `${g_testExecutionId}:${getSerialGranularity(testPath[0])}`;
|
|
180
182
|
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
183
|
+
// Serial tests intentionally collapse to a shared key (the "[serial...]"
|
|
184
|
+
// string) so that the whole group is owned by a single runner. Adding a
|
|
185
|
+
// ":dup-N" suffix would give each serial test a unique key again, breaking
|
|
186
|
+
// serialization, so we must skip the duplicate handling for them.
|
|
187
|
+
const isSerial = testPath.join(":").indexOf(SERIAL_PREFIX) !== -1;
|
|
188
|
+
|
|
189
|
+
if (!isSerial) {
|
|
190
|
+
// if this is the first attempt, we need to put a suffix to be able to
|
|
191
|
+
// parallelize duplicates in multiple runners
|
|
192
|
+
if ((this.currentTest._currentRetry || 0) === 0) {
|
|
193
|
+
g_duplicateTestKeyFullPathCount.set(
|
|
194
|
+
testKeyFullPath,
|
|
195
|
+
(g_duplicateTestKeyFullPathCount.get(testKeyFullPath) || 0) + 1
|
|
196
|
+
);
|
|
197
|
+
testKeyFullPath += `:dup-${g_duplicateTestKeyFullPathCount.get(testKeyFullPath)}`;
|
|
198
|
+
g_lastTestKeyFullPath = testKeyFullPath;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// ensure we use the same key for retries as the original attempt, otherwise
|
|
202
|
+
// we will screw up the distribution of tests; we use the last generated key
|
|
203
|
+
// since retries are executed sequentially
|
|
204
|
+
testKeyFullPath = g_lastTestKeyFullPath;
|
|
205
|
+
}
|
|
196
206
|
}
|
|
197
207
|
|
|
198
208
|
const testKey =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mocha-distributed",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.10",
|
|
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": {
|
|
@@ -28,10 +28,14 @@
|
|
|
28
28
|
"author": "Pau Sanchez",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"redis": "^
|
|
31
|
+
"redis": "^6.1.0"
|
|
32
|
+
},
|
|
33
|
+
"overrides": {
|
|
34
|
+
"diff": "^8.0.3",
|
|
35
|
+
"serialize-javascript": "^7.0.7"
|
|
32
36
|
},
|
|
33
37
|
"devDependencies": {
|
|
34
|
-
"chai": "^
|
|
35
|
-
"mocha": "^
|
|
38
|
+
"chai": "^6.2.2",
|
|
39
|
+
"mocha": "^11.7.6"
|
|
36
40
|
}
|
|
37
41
|
}
|