Skip to content

test(jobs): prove two replicas never run an exclusive job at once, and a cancelled holder hands over - #307

Merged
PiquelChips merged 1 commit into
mainfrom
test/job-runner-exclusivity
Nov 2, 2026
Merged

PiquelChips merged 1 commit into
mainfrom
test/job-runner-exclusivity

Conversation

@PiquelChips

Copy link
Copy Markdown
Member

#33 asked for a test that two job runners never overlap on the same exclusive job, and that cancelling the holder mid-run frees the lock. So far, exclusivity was only tested on the lock itself and on a single runner whose run panics. Nothing ran two Jobs runners side by side, as two replicas do.

This adds that test. Two real Jobs runners share one test database and run a test-only exclusive job. The job checks every 20 ms and holds the lock for 100 ms per run. It logs when each run starts and whether it finished or was cancelled. The cancelled entry is logged before the run's connection closes, so before the lock can be taken.

After a few runs, the test drops whichever runner is mid-run. It then expects that run to be logged as cancelled and the other runner to start. At the end, it checks that the log is all start/end pairs that never overlap.

The only production change is a test-only LockKey::ExclusivityTest, behind the test-support feature. Database tests share one database and run in parallel, so this test can't share LockKey::Test with the panic test.

Proof: just db test passes all 309 tests, and the new test passed 20 runs in a row (about 0.45 s each). I broke the code two ways and the new test failed both times:

  • letting try_exclusive hand out a lock that is already held;
  • detaching the run so dropping its runner no longer cancels it.

Reviewed with review-loop: 2 rounds with 2× GPT-6.1 Sol and Claude Opus 5.5. Verdict: approved

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by GPT-6.1 Sol and Claude Opus 5.5 (via T3 Code)

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f2b4c97-f111-4cf2-a733-21fc96c2e1c8
Commits

Reviewing files that changed from the base of the PR and between 7aa0c68 and e299f0a.

Files selected for processing: 2
  • apps/auth-service/src/jobs.rs
  • crates/database/src/exclusive/mod.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@PiquelChips
PiquelChips force-pushed the test/job-runner-exclusivity branch from 48bee9c to 6976006 Compare November 2, 2026 14:40
@PiquelChips PiquelChips self-assigned this Nov 2, 2026
@PiquelChips PiquelChips added the ci-cd CI-CD label Nov 2, 2026
@PiquelChips PiquelChips added this to the 0.1 milestone Nov 2, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Nov 2, 2026
@PiquelChips PiquelChips moved this from Needs Triage to Ready in sourceorigin.dev Nov 2, 2026
… over on cancel

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PiquelChips
PiquelChips force-pushed the test/job-runner-exclusivity branch from 6976006 to e299f0a Compare November 2, 2026 15:22
@PiquelChips
PiquelChips merged commit 08d8e11 into main Nov 2, 2026
9 checks passed
@PiquelChips
PiquelChips deleted the test/job-runner-exclusivity branch November 2, 2026 15:31
@github-project-automation github-project-automation Bot moved this from Ready to Done in sourceorigin.dev Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-cd CI-CD

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant