A store-mutating CAS fake: exactly-one-winner over the shared store.
(
store: CreatedJobRow[],
opts?: { loseFor?: (row: CreatedJobRow) => boolean },
)
| 1884 | |
| 1885 | /** A store-mutating CAS fake: exactly-one-winner over the shared store. */ |
| 1886 | function makeStoreClaim( |
| 1887 | store: CreatedJobRow[], |
| 1888 | opts?: { loseFor?: (row: CreatedJobRow) => boolean }, |
| 1889 | ): JobClaimClient { |
| 1890 | return { |
| 1891 | async claimJob(jobId, workerId): Promise<ClaimResult> { |
| 1892 | const row = store.find((r) => r.id === jobId); |
| 1893 | if (!row || row.status !== "pending") return { won: false }; |
| 1894 | if (opts?.loseFor?.(row)) return { won: false }; |
| 1895 | row.status = "claimed"; |
| 1896 | row.claimed_by = workerId; |
| 1897 | row.version += 1; |
| 1898 | return { won: true, job: { ...row } }; |
| 1899 | }, |
| 1900 | renewLease: vi.fn(async (): Promise<RenewResult> => ({ renewed: false })), |
| 1901 | releaseJob: vi.fn( |
| 1902 | async (): Promise<ReleaseResult> => ({ released: false }), |
| 1903 | ), |
| 1904 | }; |
| 1905 | } |
| 1906 | |
| 1907 | /** Seed: 60 old d4 jobs (oldest-50 page saturators) + 18 newer e2e-demos. */ |
| 1908 | function starvedStore(): CreatedJobRow[] { |
no outgoing calls
no test coverage detected
searching dependent graphs…