ref:main

Add concurrent-write CAS race test for update_branch/4 #61

open Opened by cole.christensen@gmail.com

Links

No links yet.

Problem

`ExGitObjectstore.update_branch/4` advertises compare-and-swap semantics: pass an `expected_old_sha` and the update fails with `{:error, :cas_failed}` if the ref no longer matches. `Anvil.CodeReview.rebase_pr_head/2` (in fangorn/anvil) relies on this guarantee for safety against concurrent pushes.

The Anvil-side test (`test/anvil/code_review/pr_rebase_test.exs`, "CAS failure" describe) explicitly notes that it can’t drive a real two-writer race in a single test process and asserts the contract via re-running rebase. The actual concurrency test belongs here.

Proposal

Add a test that:

  1. Spawns two processes that each call `update_branch/4` with the same `expected_old_sha` but different new SHAs.
  2. Synchronizes their start (e.g. via Task.async + ready signal).
  3. Asserts exactly one succeeds with `:ok` and the other with `{:error, :cas_failed}`.
  4. Asserts the final ref matches the winner’s new SHA.

May need to repeat under a small RNG seed loop to deflake.

Origin

Identified during fangorn/anvil#206 (PR rebase) review — surfaced the gap that this layer’s CAS contract isn’t directly tested.