Skip to content

test_at_most_one_winner_per_round counts acquisitions, not overlap — 2 winners at a 0.4s stagger #293

Closed

Description

@fdaviddpt

Found while fixing #291, in the same file, and deliberately left out of #292 because the fix is a redesign rather than a correction.

test_at_most_one_winner_per_round counts lock acquisitions per round and asserts the count is 1. That is the same mistaken invariant #291 turned out to rest on, with a wider tolerance rather than none.

Its winner releases the lock after 150 ms. A contender the OS does not schedule until after that release wins by plain mkdir — not a race, not a steal, just a later, legitimate, sequential acquisition — and the harness counts it as a concurrent winner. Measured: 2 winners at a 0.4 s stagger.

So the test currently passes because the runners it usually meets happen to schedule the contenders inside 150 ms of each other. That is the same property that made #291 fail on one ubuntu leg out of twelve and never on a laptop: the assertion is about timing, and it reads as being about the lock.

Why this is not just #291 again

#291 was fixable by pointing the contenders at _lock_try_adopt, which never consults liveness — single-winner by construction. This one cannot be fixed that way, because it is testing lock_acquire proper, and "at most one winner per round" is the property worth having there. The problem is that acquisitions are the wrong thing to count.

The honest form asserts overlap: no two contenders hold the lock at the same time. That means each contender recording an enter and an exit timestamp and the assertion checking the intervals are disjoint, rather than tallying how many got in. It is a rewrite of this file's primary test, which is why it is a decision and not a patch.

What is at stake if it is left

It is a false green today and a spurious red on some future loaded runner — and when that red arrives it will read exactly as #291 did: as evidence that the lock admits two writers. The cost of acting on that reading is high, which is why #292 added a companion test pinning the takeover semantics. This test would produce the same misdiagnosis with none of that context attached.

Also noted, unfixed

Mutating the marker clear from mv to rmdir leaves the whole file green — before #292 as well as after, verified against the original form. No teeth were removed by that PR, but that line's single-winner argument is not currently pinned by any test.

Activity

  1. added 2 commits that reference this issue on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions