@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.
@@ -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
- const [result] = await client.query(`SET @order_num = (SELECT order_num FROM ??
46
- WHERE run_id = UUID_TO_BIN(?) AND status = ?
47
- ORDER BY order_num
48
- LIMIT 1
49
- FOR UPDATE SKIP LOCKED);
50
- UPDATE ??
51
- SET status = ?, updated = CURRENT_TIMESTAMP
52
- WHERE run_id = UUID_TO_BIN(?) AND order_num = @order_num;
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[2].length === 0)
62
+ if (result[1].length === 0)
67
63
  return undefined;
68
- const { file, line, pos, project, timeout, order_num } = result[2][0];
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dionlarson/playwright-orchestrator-mysql",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "keywords": [],
5
5
  "author": "Rostyslav Kudrevatykh",
6
6
  "license": "Apache-2.0",