Skip to content

test(tiers): check for a leftover probe under the lock (#1758) - #1759

Merged
JarryShaw merged 1 commit into
mainfrom
test/1758-probe-check-under-lock
Oct 15, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
test/1758-probe-check-under-lock

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Please follow the guide below

What is the purpose of your pull request?

Tick the commit type your subject line carries.

  • fix — corrects a defect
  • feat — adds a feature
  • perf — changes performance, not behaviour
  • refactor — changes neither behaviour nor performance
  • test — tests only
  • docs — documentation only
  • ci — workflows or build tooling
  • release — bumps the version or rolls up a distribution
  • chore — anything else

Description

Closes #1758. XdistSubprocessTests.setUp in tests/test_tier_guard_xdist.py checked for a leftover probe file before taking the exclusive _tier_guard_lock. Under --dist load, a worker could see another worker's live probe and fail with "already exists".

  • Fix: the existence check now runs after lock.__enter__(). The lock release is registered before the assert, so a failing check still releases the lock. The unlink is registered after it, so cleanup still unlinks while the lock is held. ProbeWorkerCrashTests (test(tiers): keep the xdist probe out of recursive collection (#1756) #1757) already did this and is unchanged.
  • Test: ProbeLeftoverCheckTests redirects TESTS_ROOT and the lock path into a temporary directory, so it needs neither xdist nor git.
    • It holds the lock with the probe present and asserts that setUp blocks instead of failing, then that it proceeds once the probe is removed and the lock released. On the old ordering it fails with setUp did not wait for the lock: [... already exists ...].
    • A second test asserts that the lock is released when a real leftover makes the check fail.

Tests:

  • The two tier-guard modules plus test_unit_tests_queue.py give 154 passed and 3 skipped (the xdist classes skip in the repo venv).
  • Under -n 3 --dist load in an xdist venv, they give 119 passed on each of 5 runs.

XdistSubprocessTests.setUp asserted that the probe was absent before it
took the exclusive _tier_guard_lock. Under --dist load its two tests, or
ProbeWorkerCrashTests, can run on another worker, so a live probe was
reported as "already exists -- a previous run did not clean up".

- setUp now checks only after the lock is held. The release is still
  registered first, so a failed check lets go of the lock and LIFO
  cleanup still unlinks under it. ProbeWorkerCrashTests already checked
  under the lock and is unchanged.
- ProbeLeftoverCheckTests drives that setUp from a thread against a
  temporary probe directory and lock file, needing neither xdist nor git.
  It pins that setUp waits out a held lock, and that a real leftover
  fails, stays on disk, and releases the lock.

Closes #1758
@JarryShaw JarryShaw added the test Pull requests that add or correct tests (test: subject prefix) label Oct 15, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Verdict: GOOD TO GO at 3033fe4ad. A Sonnet cross-review checked 8c3ea8339 (author: Opus). Rebasing onto 1f5766c28 after #1757 merged left the patch identical (git range-diff: 8c3ea8339 = 3033fe4ad).

  • Lock released on every path:
    • skipTest returns before the lock is taken;
    • a failed check releases it, because unittest runs doCleanups after a setUp failure;
    • the test body and cleanup release it.
  • The test catches the bug. Mutated copies of the code fail it in each case:
    • old ordering: setUp did not wait for the lock;
    • release registered after the assert: setUp left the exclusive lock held;
    • check dropped: 'already exists' not found.
  • No flakes: the fixed code passed 5 reruns, then 40 runs under 8 busy-loop processes.
  • test(tiers): keep the xdist probe out of recursive collection (#1756) #1757 untouched: this PR does not change test(tiers): keep the xdist probe out of recursive collection (#1756) #1757's collect_ignore fix or ProbeWorkerCrashTests.
  • My own check, on the rebased head: the two tier-guard modules plus test_unit_tests_queue.py give 154 passed and 3 skipped, with pcapkit.__file__ printed inside the PR's worktree.

@JarryShaw JarryShaw added the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 15, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 89.59% (unit tier, Python 3.15, 3033fe4ad, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 3 20 3 95.16%
pcapkit/const 18862 954 2368 868 91.06%
pcapkit/corekit 2461 69 780 35 96.54%
pcapkit/dumpkit 276 3 100 3 98.40%
pcapkit/foundation 2915 164 1016 34 93.59%
pcapkit/interface 138 7 52 5 93.68%
pcapkit/protocols 17184 224 4574 189 98.08%
pcapkit/toolkit 872 177 298 8 77.18%
pcapkit/utilities 512 2 158 4 99.10%
pcapkit/vendor 4417 2342 1010 157 43.38%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit f4ed067 into main Oct 15, 2026
56 checks passed
@JarryShaw
JarryShaw deleted the test/1758-probe-check-under-lock branch October 15, 2026 14:58
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 15, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Pull requests that add or correct tests (test: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

test(tiers): XdistSubprocessTests checks for a leftover probe before taking the lock

1 participant