@playwright-orchestrator/mongo 1.6.0 → 1.8.0
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/dist/mongo-db-adapter.js
CHANGED
|
@@ -64,7 +64,7 @@ let MongoDbAdapter = class MongoDbAdapter extends BaseAdapter {
|
|
|
64
64
|
async saveTestResult({ runId, test, item, historyWindow, newEma }) {
|
|
65
65
|
const updatedDoc = await this.testInfo.findOneAndUpdate({ _id: test.testId }, {
|
|
66
66
|
$set: { ema: newEma },
|
|
67
|
-
// @ts-
|
|
67
|
+
// @ts-expect-error MongoDB typings reject $push with $each/$slice on this document type
|
|
68
68
|
$push: {
|
|
69
69
|
history: {
|
|
70
70
|
$each: [{ duration: item.duration, status: item.status, updated: new Date(item.updated) }],
|
|
@@ -30,8 +30,9 @@ let MongoInitializer = class MongoInitializer {
|
|
|
30
30
|
const set = new Set(collections.map((c) => c.collectionName));
|
|
31
31
|
await Promise.all([
|
|
32
32
|
!set.has(runsCollection) ? database.createCollection(runsCollection) : Promise.resolve(),
|
|
33
|
-
!set.has(testsCollection)
|
|
34
|
-
.then(c => c.createIndex({ status: 1 }))
|
|
33
|
+
!set.has(testsCollection)
|
|
34
|
+
? database.createCollection(testsCollection).then((c) => c.createIndex({ status: 1 }))
|
|
35
|
+
: Promise.resolve(),
|
|
35
36
|
!set.has(testsInfoCollection) ? database.createCollection(testsInfoCollection) : Promise.resolve(),
|
|
36
37
|
]);
|
|
37
38
|
}
|
|
@@ -12,6 +12,7 @@ export declare class MongoShardHandler implements ShardHandler {
|
|
|
12
12
|
getNextTestByProject(project: string): Promise<TestItem | undefined>;
|
|
13
13
|
private claimNextTest;
|
|
14
14
|
startShard(): Promise<TestRunConfig>;
|
|
15
|
+
heartbeat(): Promise<void>;
|
|
15
16
|
finishShard(): Promise<void>;
|
|
16
17
|
private get runs();
|
|
17
18
|
private get tests();
|
|
@@ -11,7 +11,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
import { injectable, inject } from 'inversify';
|
|
14
|
-
import { RunStatus, SYMBOLS, TestStatus } from '@playwright-orchestrator/core';
|
|
14
|
+
import { getAliveUntil, getDeadShardIds, RunStatus, SYMBOLS, TestStatus } from '@playwright-orchestrator/core';
|
|
15
15
|
import { MongoConnection } from './mongo-connection.js';
|
|
16
16
|
import { MONGO_CONFIG, MONGO_CONNECTION } from './symbols.js';
|
|
17
17
|
import { generateTestId, generateRunId, parseTestId } from './helpers.js';
|
|
@@ -38,7 +38,11 @@ let MongoShardHandler = class MongoShardHandler {
|
|
|
38
38
|
? { ...this.generateTestIdQuery(runId, TestStatus.Ready), 'meta.projects': project }
|
|
39
39
|
: this.generateTestIdQuery(runId, TestStatus.Ready);
|
|
40
40
|
const result = await this.tests.findOneAndUpdate(query, {
|
|
41
|
-
$set: {
|
|
41
|
+
$set: {
|
|
42
|
+
updated: new Date(),
|
|
43
|
+
status: TestStatus.Ongoing,
|
|
44
|
+
'meta.shardId': this.runContext.shardId,
|
|
45
|
+
},
|
|
42
46
|
});
|
|
43
47
|
if (!result)
|
|
44
48
|
return undefined;
|
|
@@ -62,8 +66,12 @@ let MongoShardHandler = class MongoShardHandler {
|
|
|
62
66
|
else: RunStatus.RepeatRun,
|
|
63
67
|
},
|
|
64
68
|
},
|
|
69
|
+
// A shard with the same id keeps its record, with a new aliveUntil
|
|
65
70
|
[`shards.${shardId}`]: {
|
|
66
|
-
$
|
|
71
|
+
$mergeObjects: [
|
|
72
|
+
{ $ifNull: [`$shards.${shardId}`, { shardId, started: nowMs }] },
|
|
73
|
+
{ aliveUntil: getAliveUntil(this.runContext.heartbeatTimeout) },
|
|
74
|
+
],
|
|
67
75
|
},
|
|
68
76
|
updated: now,
|
|
69
77
|
},
|
|
@@ -72,6 +80,13 @@ let MongoShardHandler = class MongoShardHandler {
|
|
|
72
80
|
if (!run)
|
|
73
81
|
throw new Error(`Run ${runId} not found`);
|
|
74
82
|
const { status: statusBefore } = run;
|
|
83
|
+
if (statusBefore === RunStatus.Finished) {
|
|
84
|
+
// Claimed tests without a result whose shard died
|
|
85
|
+
await this.tests.updateMany({
|
|
86
|
+
...this.generateTestIdQuery(runId, TestStatus.Ongoing),
|
|
87
|
+
'meta.shardId': { $in: getDeadShardIds(run.shards, shardId) },
|
|
88
|
+
}, { $set: { status: TestStatus.Ready, updated: now } });
|
|
89
|
+
}
|
|
75
90
|
if (statusBefore === RunStatus.Created || statusBefore === RunStatus.Finished) {
|
|
76
91
|
await this.tests.updateMany(this.generateTestIdQuery(runId, TestStatus.Failed), {
|
|
77
92
|
$set: { status: TestStatus.Ready, updated: now },
|
|
@@ -88,6 +103,10 @@ let MongoShardHandler = class MongoShardHandler {
|
|
|
88
103
|
}
|
|
89
104
|
return run.config;
|
|
90
105
|
}
|
|
106
|
+
async heartbeat() {
|
|
107
|
+
const { runId, shardId, heartbeatTimeout } = this.runContext;
|
|
108
|
+
await this.runs.updateOne({ _id: generateRunId(runId) }, { $set: { [`shards.${shardId}.aliveUntil`]: getAliveUntil(heartbeatTimeout) } });
|
|
109
|
+
}
|
|
91
110
|
async finishShard() {
|
|
92
111
|
const { runId, shardId } = this.runContext;
|
|
93
112
|
const now = new Date();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright-orchestrator/mongo",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": "Rostyslav Kudrevatykh",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"inversify": "^8.0.0-beta.0",
|
|
19
19
|
"mongodb": "^6.12.0",
|
|
20
20
|
"uuid": "^14.0.0",
|
|
21
|
-
"@playwright-orchestrator/core": "1.
|
|
21
|
+
"@playwright-orchestrator/core": "1.8.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {},
|
|
24
24
|
"main": "dist/index.js",
|