Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
442 changes: 442 additions & 0 deletions tests/_spawn_lock.py

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion tests/test_coord_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import pytest

from tests._spawn_lock import spawn_burst

LOCK = Path(__file__).resolve().parents[1] / "scripts" / "coord" / "lock.ps1"

pytestmark = pytest.mark.skipif(
Expand Down Expand Up @@ -141,7 +143,13 @@ def test_eight_concurrent_claimants_never_hold_it_at_once(repo: Path, tmp_path:
barrier = tmp_path / "barrier"
barrier.mkdir()

with ThreadPoolExecutor(max_workers=8) as pool:
# Eight concurrent pwsh, and the winner holds for 8 s -- the same shape as the storm BACKLOG #1304
# is about, found by sweeping the tier rather than by CI evidence. Nothing about the claimants
# changes; the lock only keeps single-launch tests off these vCPUs while they run.
with (
spawn_burst("coord_lock.mutex_under_load x8"),
ThreadPoolExecutor(max_workers=8) as pool,
):
claims = [
pool.submit(
acquire,
Expand Down
14 changes: 12 additions & 2 deletions tests/test_session_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

import pytest

from tests._spawn_lock import spawn_burst

ROOT = Path(__file__).resolve().parents[1]
COORD = ROOT / "scripts" / "coord"
HOOKS = ROOT / "scripts" / "hooks"
Expand Down Expand Up @@ -653,7 +655,12 @@ def one(i: int) -> subprocess.CompletedProcess[str]:
capture_output=True, text=True, timeout=240, check=False,
) # fmt: skip

with concurrent.futures.ThreadPoolExecutor(max_workers=RACERS) as ex:
# RACERS stays 16 -- see tests/_spawn_lock.py for why cutting it is the wrong fix. The burst lock
# keeps single-launch tests off these vCPUs while the storm runs, without changing what runs here.
with (
spawn_burst(f"session_mail._race {mode} x{RACERS}"),
concurrent.futures.ThreadPoolExecutor(max_workers=RACERS) as ex,
):
procs = [f.result() for f in [ex.submit(one, i) for i in range(1, RACERS + 1)]]
rows: list[dict[str, Any]] = []
for p in procs:
Expand Down Expand Up @@ -948,7 +955,10 @@ def test_concurrent_drains_deliver_one_message_once(repo: Path, tmp_path: Path)
def one(_: int) -> subprocess.CompletedProcess[str]:
return run_drain(repo)

with concurrent.futures.ThreadPoolExecutor(max_workers=DRAINS) as ex:
with (
spawn_burst(f"session_mail.concurrent_drains x{DRAINS}"),
concurrent.futures.ThreadPoolExecutor(max_workers=DRAINS) as ex,
):
procs = [f.result() for f in [ex.submit(one, i) for i in range(DRAINS)]]

texts = [injection(p) for p in procs]
Expand Down
Loading
Loading