summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-12-08 17:38:42 -0500
committerbd <bdunahu@operationnull.com>2025-12-08 17:38:42 -0500
commit412c8225046b7549e0b02425f5140f2a33abac8a (patch)
tree3b1986b9a43f0e14f6ed591602c159a46ecfb3c5 /t
parent782050b9b648ef788e5695a5556b401d4ab66849 (diff)
ex: add examples
Diffstat (limited to 't')
-rw-r--r--t/block_longtime.py30
-rw-r--r--t/block_shell_longtime.py30
2 files changed, 60 insertions, 0 deletions
diff --git a/t/block_longtime.py b/t/block_longtime.py
new file mode 100644
index 0000000..d848228
--- /dev/null
+++ b/t/block_longtime.py
@@ -0,0 +1,30 @@
+import asyncio
+import time
+import sys
+import os
+sys.path.append(os.path.expanduser('~/nemesis/'))
+from nemesis.causal_event_loop import causal_loop_factory
+
+
+async def burn_cpu(sec):
+ t0 = time.perf_counter()
+ elapsed = 0
+ while (elapsed < sec):
+ for _ in range(1000):
+ pass
+ elapsed = time.perf_counter() - t0
+
+async def sleep_task(duration):
+ await asyncio.sleep(duration)
+
+async def main():
+ total_duration = 90
+ sleep_durations = [1.0, 0.7, 0.7, 0.4]
+
+ for _ in range(total_duration):
+ tasks = [asyncio.create_task(sleep_task(duration)) for duration in sleep_durations]
+ burn_task = asyncio.create_task(burn_cpu(1))
+
+ await asyncio.gather(burn_task, *tasks)
+
+asyncio.run(main(), loop_factory=causal_loop_factory)
diff --git a/t/block_shell_longtime.py b/t/block_shell_longtime.py
new file mode 100644
index 0000000..8d31dd8
--- /dev/null
+++ b/t/block_shell_longtime.py
@@ -0,0 +1,30 @@
+import asyncio
+import sys
+import os
+sys.path.append(os.path.expanduser('~/nemesis/'))
+from nemesis.causal_event_loop import causal_loop_factory
+import time
+
+
+async def burn_cpu(sec):
+ t0 = time.perf_counter()
+ elapsed = 0
+ while (elapsed < sec):
+ for _ in range(1000):
+ pass
+ elapsed = time.perf_counter() - t0
+
+async def sleep_task(duration):
+ await asyncio.create_subprocess_shell(f'sleep {duration}')
+
+async def main():
+ total_duration = 90
+ sleep_durations = [1.0, 0.4, 0.7, 0.7]
+
+ for _ in range(total_duration):
+ tasks = [asyncio.create_task(sleep_task(duration)) for duration in sleep_durations]
+ burn_task = asyncio.create_task(burn_cpu(1))
+
+ await asyncio.gather(burn_task, *tasks)
+
+asyncio.run(main(), loop_factory=causal_loop_factory)