@dionlarson/playwright-orchestrator-mysql 1.4.0 → 1.5.1
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/mysql-adapter.js +12 -16
- package/package.json +1 -1
package/dist/mysql-adapter.js
CHANGED
|
@@ -42,30 +42,26 @@ export class MySQLAdapter extends Adapter {
|
|
|
42
42
|
const client = await this.pool.getConnection();
|
|
43
43
|
try {
|
|
44
44
|
await client.beginTransaction();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
SELECT * FROM ??
|
|
55
|
-
WHERE run_id = UUID_TO_BIN(?) AND order_num = @order_num`, [
|
|
56
|
-
this.testsTable,
|
|
57
|
-
runId,
|
|
58
|
-
TestStatus.Ready,
|
|
45
|
+
// Use UPDATE ... ORDER BY ... LIMIT 1 for truly atomic claim.
|
|
46
|
+
// This locks exactly one row during the UPDATE, preventing race conditions.
|
|
47
|
+
// Store the claimed order_num in a session variable for the subsequent SELECT.
|
|
48
|
+
const [result] = await client.query(`UPDATE ?? SET status = ?, updated = CURRENT_TIMESTAMP, order_num = (@claimed_order := order_num)
|
|
49
|
+
WHERE run_id = UUID_TO_BIN(?) AND status = ?
|
|
50
|
+
ORDER BY order_num
|
|
51
|
+
LIMIT 1;
|
|
52
|
+
|
|
53
|
+
SELECT * FROM ?? WHERE run_id = UUID_TO_BIN(?) AND order_num = @claimed_order`, [
|
|
59
54
|
this.testsTable,
|
|
60
55
|
TestStatus.Ongoing,
|
|
61
56
|
runId,
|
|
57
|
+
TestStatus.Ready,
|
|
62
58
|
this.testsTable,
|
|
63
59
|
runId,
|
|
64
60
|
]);
|
|
65
61
|
await client.commit();
|
|
66
|
-
if (result[
|
|
62
|
+
if (result[1].length === 0)
|
|
67
63
|
return undefined;
|
|
68
|
-
const { file, line, pos, project, timeout, order_num } = result[
|
|
64
|
+
const { file, line, pos, project, timeout, order_num } = result[1][0];
|
|
69
65
|
return { file, position: `${line}:${pos}`, project, timeout, order: order_num };
|
|
70
66
|
}
|
|
71
67
|
catch (e) {
|