@dionlarson/playwright-orchestrator-pg 1.3.8 → 1.4.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.
|
@@ -16,6 +16,7 @@ export declare class PostgreSQLAdapter extends Adapter {
|
|
|
16
16
|
startShard(runId: string): Promise<TestRunConfig>;
|
|
17
17
|
finishShard(runId: string): Promise<void>;
|
|
18
18
|
dispose(): Promise<void>;
|
|
19
|
+
cleanupStaleTests(runId: string, staleMinutes: number): Promise<number>;
|
|
19
20
|
getReportData(runId: string): Promise<TestRunReport>;
|
|
20
21
|
private updateTestWithResults;
|
|
21
22
|
private loadTestInfos;
|
|
@@ -26,6 +26,7 @@ export class PostgreSQLAdapter extends Adapter {
|
|
|
26
26
|
async getNextTest(runId, config) {
|
|
27
27
|
const client = await this.pool.connect();
|
|
28
28
|
try {
|
|
29
|
+
console.log(`[pg-adapter] getNextTest: BEGIN transaction`);
|
|
29
30
|
await client.query('BEGIN');
|
|
30
31
|
const result = await client.query({
|
|
31
32
|
text: `WITH next_test AS (
|
|
@@ -42,14 +43,17 @@ export class PostgreSQLAdapter extends Adapter {
|
|
|
42
43
|
RETURNING *`,
|
|
43
44
|
values: [runId, TestStatus.Ready, TestStatus.Ongoing],
|
|
44
45
|
});
|
|
46
|
+
console.log(`[pg-adapter] getNextTest: got ${result.rowCount} rows, order_num=${result.rows[0]?.order_num}`);
|
|
45
47
|
await client.query('COMMIT');
|
|
48
|
+
console.log(`[pg-adapter] getNextTest: COMMIT`);
|
|
46
49
|
if (result.rowCount === 0)
|
|
47
50
|
return undefined;
|
|
48
51
|
const { file, line, character, project, timeout, order_num } = result.rows[0];
|
|
49
52
|
return { file, position: `${line}:${character}`, project, timeout, order: order_num };
|
|
50
53
|
}
|
|
51
54
|
catch (e) {
|
|
52
|
-
|
|
55
|
+
console.log(`[pg-adapter] getNextTest: ERROR ${e}, rolling back`);
|
|
56
|
+
await client.query('ROLLBACK');
|
|
53
57
|
}
|
|
54
58
|
finally {
|
|
55
59
|
client.release();
|
|
@@ -197,6 +201,17 @@ export class PostgreSQLAdapter extends Adapter {
|
|
|
197
201
|
return;
|
|
198
202
|
await this.pool.end();
|
|
199
203
|
}
|
|
204
|
+
async cleanupStaleTests(runId, staleMinutes) {
|
|
205
|
+
const result = await this.pool.query({
|
|
206
|
+
text: `UPDATE ${this.testsTable}
|
|
207
|
+
SET status = $1, updated = NOW()
|
|
208
|
+
WHERE run_id = $2
|
|
209
|
+
AND status = $3
|
|
210
|
+
AND updated < NOW() - INTERVAL '1 minute' * $4`,
|
|
211
|
+
values: [TestStatus.Ready, runId, TestStatus.Ongoing, staleMinutes],
|
|
212
|
+
});
|
|
213
|
+
return result.rowCount ?? 0;
|
|
214
|
+
}
|
|
200
215
|
async getReportData(runId) {
|
|
201
216
|
const { rows: [dbConfig], } = await this.pool.query({
|
|
202
217
|
text: `SELECT * FROM ${this.configTable} WHERE id = $1`,
|
|
@@ -227,22 +242,28 @@ export class PostgreSQLAdapter extends Adapter {
|
|
|
227
242
|
async updateTestWithResults(status, { runId, test, config, testResult }) {
|
|
228
243
|
const testId = this.getTestId({ ...test, ...testResult });
|
|
229
244
|
const { rows: [testInfo], } = await this.pool.query({
|
|
230
|
-
text: `SELECT
|
|
231
|
-
id,
|
|
245
|
+
text: `SELECT
|
|
246
|
+
id,
|
|
232
247
|
ema,
|
|
233
248
|
(
|
|
234
|
-
SELECT COUNT(*) FROM ${this.testInfoHistoryTable}
|
|
249
|
+
SELECT COUNT(*) FROM ${this.testInfoHistoryTable}
|
|
235
250
|
WHERE status = ${TestStatus.Failed} AND test_info_id = info.id
|
|
236
251
|
) AS fails,
|
|
237
252
|
(
|
|
238
|
-
SELECT updated FROM ${this.testInfoHistoryTable}
|
|
239
|
-
WHERE status = ${TestStatus.Passed} AND test_info_id = info.id
|
|
253
|
+
SELECT updated FROM ${this.testInfoHistoryTable}
|
|
254
|
+
WHERE status = ${TestStatus.Passed} AND test_info_id = info.id
|
|
240
255
|
ORDER BY updated DESC LIMIT 1
|
|
241
256
|
) AS last_successful_run
|
|
242
257
|
FROM ${this.testInfoTable} info
|
|
243
258
|
WHERE name = $1`,
|
|
244
259
|
values: [testId],
|
|
245
260
|
});
|
|
261
|
+
// Test not found in database - this shouldn't happen as saveTestRun should create it
|
|
262
|
+
// But handle gracefully to avoid crashes
|
|
263
|
+
if (!testInfo) {
|
|
264
|
+
console.warn(`[pg-adapter] Test not found in database: ${testId}`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
246
267
|
const report = {
|
|
247
268
|
title: testResult.title,
|
|
248
269
|
status,
|