@playwright-orchestrator/mongo 1.7.0 → 1.9.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/README.md CHANGED
@@ -1,3 +1,5 @@
1
1
  # Playwright Orchestrator MongoDB plugin
2
2
 
3
- For more details visit @[playwright-orchestrator/core](https://www.npmjs.com/package/@playwright-orchestrator/core) page
3
+ Storage adapter for [Playwright Orchestrator](https://rostmanrk.github.io/playwright-orchestrator/). Install it next to [@playwright-orchestrator/core](https://www.npmjs.com/package/@playwright-orchestrator/core).
4
+
5
+ Options and setup: [mongo adapter docs](https://rostmanrk.github.io/playwright-orchestrator/guide/adapters/mongo).
@@ -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: { updated: new Date(), status: TestStatus.Ongoing },
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;
@@ -63,7 +67,10 @@ let MongoShardHandler = class MongoShardHandler {
63
67
  },
64
68
  },
65
69
  [`shards.${shardId}`]: {
66
- $ifNull: [`$shards.${shardId}`, { shardId, started: nowMs }],
70
+ $mergeObjects: [
71
+ { $ifNull: [`$shards.${shardId}`, { shardId, started: nowMs }] },
72
+ { aliveUntil: getAliveUntil(this.runContext.heartbeatTimeout) },
73
+ ],
67
74
  },
68
75
  updated: now,
69
76
  },
@@ -72,6 +79,12 @@ let MongoShardHandler = class MongoShardHandler {
72
79
  if (!run)
73
80
  throw new Error(`Run ${runId} not found`);
74
81
  const { status: statusBefore } = run;
82
+ if (statusBefore === RunStatus.Finished) {
83
+ await this.tests.updateMany({
84
+ ...this.generateTestIdQuery(runId, TestStatus.Ongoing),
85
+ 'meta.shardId': { $in: getDeadShardIds(run.shards, shardId) },
86
+ }, { $set: { status: TestStatus.Ready, updated: now } });
87
+ }
75
88
  if (statusBefore === RunStatus.Created || statusBefore === RunStatus.Finished) {
76
89
  await this.tests.updateMany(this.generateTestIdQuery(runId, TestStatus.Failed), {
77
90
  $set: { status: TestStatus.Ready, updated: now },
@@ -88,6 +101,10 @@ let MongoShardHandler = class MongoShardHandler {
88
101
  }
89
102
  return run.config;
90
103
  }
104
+ async heartbeat() {
105
+ const { runId, shardId, heartbeatTimeout } = this.runContext;
106
+ await this.runs.updateOne({ _id: generateRunId(runId) }, { $set: { [`shards.${shardId}.aliveUntil`]: getAliveUntil(heartbeatTimeout) } });
107
+ }
91
108
  async finishShard() {
92
109
  const { runId, shardId } = this.runContext;
93
110
  const now = new Date();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright-orchestrator/mongo",
3
- "version": "1.7.0",
3
+ "version": "1.9.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.7.0"
21
+ "@playwright-orchestrator/core": "1.9.0"
22
22
  },
23
23
  "devDependencies": {},
24
24
  "main": "dist/index.js",