Skip to content

Commit 80865cc

Browse files
codeSamuraiiCopilot
andcommitted
More test fixes
Co-authored-by: Copilot <copilot@github.com>
1 parent 4a7cb3c commit 80865cc

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

tests/test_e2e.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,31 @@ async def very_slow(n: int) -> int:
280280

281281
class TestRetryAndTimeout:
282282
async def test_retry_on_failure(self, worker: subprocess.Popen[bytes]) -> None:
283-
@trace(retries=3, retry_delay=0.1)
284-
def sometimes_fails() -> str:
285-
import random
286-
random.seed() # re-seed each call
287-
if random.random() < 0.3:
288-
raise RuntimeError("transient")
289-
return "ok"
283+
# Deterministic retry test: a counter file local to the worker
284+
# process records how many attempts have been made. The first
285+
# two raise; the third succeeds. This avoids RNG flakes while
286+
# still exercising the full retry path. The path lives on
287+
# whichever filesystem actually runs the function -- the host
288+
# worker's /tmp, or the sandbox container's /tmp.
289+
import uuid
290+
counter_path = f"/tmp/pyfuse-retry-{uuid.uuid4().hex}.txt"
290291

291-
# With 3 retries, at least one attempt should succeed (very high probability)
292-
result = await sometimes_fails.run()
293-
assert result == "ok"
292+
@trace(retries=3, retry_delay=0.1)
293+
def fails_then_succeeds(path: str, fail_until: int) -> str:
294+
import os
295+
n = 0
296+
if os.path.exists(path):
297+
with open(path) as f:
298+
n = int(f.read() or "0")
299+
n += 1
300+
with open(path, "w") as f:
301+
f.write(str(n))
302+
if n <= fail_until:
303+
raise RuntimeError(f"transient (attempt {n})")
304+
return f"ok after {n} attempts"
305+
306+
result = await fails_then_succeeds.run(counter_path, 2)
307+
assert result == "ok after 3 attempts"
294308

295309

296310
class TestScheduling:

tests/test_sandbox.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ async def test_end_to_end(self) -> None:
276276
class TestDockerSandbox:
277277
def test_default_params(self) -> None:
278278
sb = DockerSandbox()
279-
assert sb.image == "pyfuse-sandbox"
279+
# The default tag embeds a content hash of the bundled image
280+
# assets so changes to the Dockerfile / guest agent invalidate
281+
# any previously-built image.
282+
assert sb.image.startswith("pyfuse-sandbox:")
280283
assert sb.container_name == "pyfuse-sandbox"
281284
assert sb.guest_port == 9749
282285
assert sb.cpus == 2

0 commit comments

Comments
 (0)