Skip to content

Commit 1287c4a

Browse files
committed
timebox chaos tests
1 parent c0eea6f commit 1287c4a

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

tests/chaos/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Chaos tests are opt-in and skipped by default.
1414
RUN_CHAOS_TESTS=1 pytest -q tests/chaos -q
1515
```
1616

17+
Default timeout is 60s (set `CHAOS_TEST_TIMEOUT_SECONDS` to override) so runs cannot hang CI.
18+
1719
## What is simulated
1820

1921
- A transport-level stub for `httpx.Client` (used by the SDK REST layer) that:

tests/chaos/test_task_handler_chaos.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import signal
23
import time
34
import unittest
45
from multiprocessing import Value
@@ -75,6 +76,14 @@ def request(self, method, url, params=None, content=None, timeout=None, headers=
7576
@unittest.skipIf(os.name == "nt", "Chaos tests rely on fork semantics on POSIX")
7677
class TestTaskHandlerChaos(unittest.TestCase):
7778
def setUp(self) -> None:
79+
# Hard stop to prevent runaway chaos runs (default 60s, override via CHAOS_TEST_TIMEOUT_SECONDS)
80+
timeout = int(os.getenv("CHAOS_TEST_TIMEOUT_SECONDS", "60"))
81+
try:
82+
signal.alarm(timeout)
83+
except Exception:
84+
# On platforms without alarm (should be skipped anyway)
85+
pass
86+
7887
with _client_creations.get_lock():
7988
_client_creations.value = 0
8089
with _requests_total.get_lock():
@@ -90,6 +99,10 @@ def setUp(self) -> None:
9099
self._patcher.start()
91100

92101
def tearDown(self) -> None:
102+
try:
103+
signal.alarm(0)
104+
except Exception:
105+
pass
93106
try:
94107
self._patcher.stop()
95108
except Exception:
@@ -161,4 +174,3 @@ def test_worker_process_restarts_after_kill(self):
161174
self.assertGreaterEqual(status1["restart_count"], 1)
162175
self.assertNotEqual(status1["pid"], old_pid)
163176
self.assertTrue(status1["alive"])
164-

0 commit comments

Comments
 (0)