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
10 changes: 9 additions & 1 deletion tests/test_backlog2394_database_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,15 @@ async def test_a_retried_close_waits_on_the_close_already_in_flight(
assert await asyncio.wait_for(sending, WAIT) is None
await asyncio.wait_for(retry, WAIT)
assert destination._pool is None and rig.pools[0].waits == 1
assert rig.pools[0] not in database._CLOSING, "a finished close is still tracked"
# The close forgets itself in a done callback, queued when wait_closed ends. On a loaded runner
# the retry's tick timer can wake it in that same pass, ahead of the close's last step, so the
# retry ends before that callback runs. If the send also ended then, this task resumes between
# the two, finds ``retry`` already done, and the await above returns without yielding: read at
# once the entry is still there (CI run 46876329705). A close that never forgets itself still
# fails here, once WAIT runs out.
assert await wait_until(lambda: rig.pools[0] not in database._CLOSING), (
"a finished close is still tracked"
)


class _FailingClose:
Expand Down
27 changes: 26 additions & 1 deletion tests/test_dicom_scp.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,36 @@ async def gated_handler(data: bytes) -> IngressReceipt:
await release_commit.wait() # park mid-commit until the test releases it
return IngressReceipt.accepted("mid-gated") # the receipt: committed

def cstore_then_abort(port: int, data: bytes) -> tuple[bool, int | None]:
# _scu_cstore, ended with an A-ABORT instead of a release. The SCP is stopping by then, so
# it ends a release with an abort at once, and pynetdicom 3.0.4's requestor can lose that:
# release() pauses the reactor by trusting _is_paused, which still reads True for the
# reactor send_c_store has just woken. That reactor's next pass takes the abort off the
# queue, and release() waits out the SCU's 30 s ACSE timeout (CI run 46854824199). Nothing
# this test proves rides on how the SCU ends; the C-STORE status is read before it does.
from pydicom import dcmread
from pynetdicom import AE

ds = dcmread(BytesIO(data))
ae = AE(ae_title="MODALITY1")
ae.add_requested_context(ds.SOPClassUID, ds.file_meta.TransferSyntaxUID)
assoc = ae.associate("127.0.0.1", port, ae_title=_SCP_AE)
if not assoc.is_established:
return (False, None)
try:
status = assoc.send_c_store(ds)
# No Status when the association ended before the reply, as a stop that aborted would.
return (True, int(status.Status) if "Status" in status else None)
finally:
assoc.abort()

scp = _build_scp(captured)
await scp.start(receipt_handler(gated_handler))
try:
# Fire the SCU C-STORE off-thread; it parks inside send_c_store awaiting the reply.
cstore = asyncio.create_task(asyncio.to_thread(_scu_cstore, scp.sockport, make_sr_part10()))
cstore = asyncio.create_task(
asyncio.to_thread(cstore_then_abort, scp.sockport, make_sr_part10())
)
await asyncio.wait_for(commit_begun.wait(), timeout=15)
assert len(captured) == 1, "the in-flight commit must have begun before we stop"

Expand Down
14 changes: 11 additions & 3 deletions tests/test_durability_hook_push_bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@
)


#: How far below ``time.time()`` a census starts. On Linux psutil builds a creation time from
#: ``/proc/stat``'s ``btime``, which the kernel truncates to whole seconds, plus the start time
#: truncated to clock ticks, so a process can read up to about 1.01s EARLIER than it started. A 1.0s
#: margin then misses one started within a tick of the cut, and psutil caches the value per process,
#: so every later poll misses it too: CI run 46868850826, "the teardown census did not see the frozen
#: process". A wall-clock step back by more than the margin is not covered. The needles alone tie a
#: process to its test, so a wider margin admits no other test's process.
CENSUS_MARGIN = 3.0
#: Nothing this file starts predates its import, so older processes are skipped unread: see
#: ``_ours`` for what a full command-line walk costs on a loaded box.
_IMPORTED = time.time() - 1.0
_IMPORTED = time.time() - CENSUS_MARGIN


def _matching(token: str) -> list[str]:
Expand Down Expand Up @@ -300,7 +308,7 @@ def token(tmp_path: Path, jobs: list[int]) -> Iterator[str]:
outlives it -- on failure as well as on success."""
value = uuid.uuid4().hex[:12]
# A margin below now, so a process started in this same instant still counts as this test's.
since = time.time() - 1.0
since = time.time() - CENSUS_MARGIN
try:
yield value
finally:
Expand Down Expand Up @@ -497,7 +505,7 @@ def test_the_TEARDOWN_ends_a_SUSPENDED_process_frozen_before_it_ran(
job. On Windows it is created suspended and never resumed, which is what a shell killed between
``CreateProcess(CREATE_SUSPENDED)`` and the resume leaves; elsewhere it is stopped on start. The
census must SEE it first, or "nothing survived" would only mean nothing was found."""
since = time.time() - 1.0
since = time.time() - CENSUS_MARGIN
frozen = subprocess.Popen( # noqa: S603 - fixed argv, no shell
[sys.executable, "-c", "import time; time.sleep(60)", token],
cwd=tmp_path,
Expand Down
31 changes: 25 additions & 6 deletions tests/test_sandbox_isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os
import threading
import time
from collections.abc import Callable
from decimal import Decimal
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -1017,14 +1018,32 @@ def slow_refusal(lookup: codec.LookupRequest) -> str:
env=None,
graph=None,
)

retry_until = time.monotonic() + 30.0 # inside the 60 s per-test watchdog

def dispatch_until(reached: Callable[[], bool], what: str) -> None:
# On a loaded runner a worker can send its lookup only after its cap fired, or its helper
# can start only then (CI run 46863103581). That dispatch served nothing: it neither calls
# the runner nor builds a refusal, so it is sent again. Every dispatch still hits the cap.
while True:
with pytest.raises(SandboxError, match="exceeded the 4.0s wall cap"):
_bodies(registry, "h_db", session)
assert len(calls) <= 1, "a second runner call started on the hung connection"
if reached():
return
if time.monotonic() > retry_until:
pytest.fail(f"no dispatch {what} before the retry budget ran out")

try:
with db_lookup_mod.activated(hung):
for _ in range(3): # A hangs; B and C each find the connection busy
with pytest.raises(SandboxError, match="exceeded the 4.0s wall cap"):
_bodies(registry, "h_db", session)
# B's and C's helpers must be over before the count is read, or a late call could land
# after it. Each named itself in the refusal it was building when its cap fired.
assert len(refusing_helpers) == 2
dispatch_until(lambda: bool(calls), "reached the runner") # A hangs
# B and C each find the connection busy.
dispatch_until(lambda: len(refusing_helpers) >= 1, "found the connection busy")
dispatch_until(lambda: len(refusing_helpers) >= 2, "found the connection busy")
# Every refusing helper must be over before the count is read, or a late call could
# land after it. Each named itself in the refusal it was building when its cap fired;
# a retry can add one beyond B's and C's. A helper too late to refuse returned before
# it could register, so it never reaches the runner either.
for thread in refusing_helpers:
thread.join(10)
assert not thread.is_alive()
Expand Down