Skip to content

Commit f1a7150

Browse files
committed
test: apply perfected test logic from backup branch
1 parent a7e91b1 commit f1a7150

3 files changed

Lines changed: 152 additions & 152 deletions

File tree

src/omnipkg/core.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def _get_dynamic_omnipkg_version():
127127

128128
if not HAS_TOMLLIB:
129129
# Can't read TOML, try metadata
130-
import requests as http_requests
131130
try:
132131
return importlib.metadata.version("omnipkg")
133132
except (importlib.metadata.PackageNotFoundError, Exception):
@@ -2315,13 +2314,6 @@ def get_actual_current_site_packages(self) -> Path:
23152314
This is more reliable than calculating it from sys.prefix when hotswapping is involved.
23162315
Cross-platform compatible with special handling for Windows.
23172316
"""
2318-
rebuild_cmd = [
2319-
str(final_config["python_executable"]),
2320-
"-m",
2321-
"omnipkg.cli",
2322-
"reset",
2323-
"-y",
2324-
]
23252317
is_windows = platform.system() == "Windows"
23262318

23272319
try:
@@ -4163,9 +4155,6 @@ def _heal_corrupt_metadata(self, install_path: Path, expected_package_name: str)
41634155
def create_bubble_for_package(
41644156
self, package_name: str, version: str, python_context_version: str
41654157
) -> bool:
4166-
# --- ADD THIS LINE HERE ---
4167-
import site as site_module
4168-
41694158
"""
41704159
Creates a complete, isolated bubble for a package, including all its dependencies.
41714160
For editable/dev installs, copies directly from the source directory.

src/tests/test_loader_stress_test.py

Lines changed: 79 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Import the daemon client
1919
try:
2020
from omnipkg.loader import omnipkgLoader
21-
from omnipkg.isolation.worker_daemon import DaemonClient, WorkerPoolDaemon
21+
from omnipkg.isolation.worker_daemon import DaemonClient
2222
except ImportError:
2323
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
2424
"""
@@ -93,6 +93,53 @@ def print_chaos_header():
9393
# have been removed in favor of the imported versions from omnipkg.isolation!
9494

9595

96+
97+
# ═══════════════════════════════════════════════════════════
98+
# 🔧 CANONICAL DAEMON START HELPER
99+
# Never call WorkerPoolDaemon().start(daemonize=True) from inside a running
100+
# process — that forks and then sys.exit(0)s the parent, killing the test
101+
# runner. Always use this instead: subprocess + poll.
102+
# ═══════════════════════════════════════════════════════════
103+
def ensure_daemon_running(warmup_specs=None, timeout: float = 30.0) -> bool:
104+
"""
105+
Start the daemon if it isn't already running, then poll until it answers.
106+
Safe to call from any context — uses subprocess so the current process
107+
is never forked/killed. warmup_specs is accepted but ignored (the daemon
108+
picks up its own config on start).
109+
"""
110+
try:
111+
from omnipkg.isolation.worker_daemon import DaemonClient
112+
client = DaemonClient()
113+
if client.status().get("success"):
114+
return True
115+
116+
safe_print(" ⚙️ Starting daemon...")
117+
proc = subprocess.Popen(
118+
["8pkg", "daemon", "start"],
119+
stdout=subprocess.DEVNULL,
120+
stderr=subprocess.DEVNULL,
121+
)
122+
deadline = time.monotonic() + timeout
123+
while time.monotonic() < deadline:
124+
time.sleep(0.5)
125+
rc = proc.poll()
126+
if rc is not None and rc != 0:
127+
safe_print(f" ❌ Daemon launcher exited rc={rc}")
128+
return False
129+
if client.status().get("success"):
130+
safe_print(" ✅ Daemon up")
131+
return True
132+
proc.kill()
133+
safe_print(f" ❌ Daemon never came up after {timeout:.0f}s")
134+
return False
135+
except ImportError:
136+
safe_print(" ❌ Daemon modules missing.")
137+
return False
138+
except Exception as e:
139+
safe_print(f" ❌ ensure_daemon_running failed: {e}")
140+
return False
141+
142+
96143
def chaos_test_1_version_tornado():
97144
"""🌪️ TEST 1: VERSION TORNADO - Compare Legacy vs Daemon WITH WARMUP"""
98145
safe_print("╔══════════════════════════════════════════════════════════════╗")
@@ -433,14 +480,13 @@ def go_deeper_legacy(level):
433480
from omnipkg.isolation.worker_daemon import (
434481
DaemonClient,
435482
DaemonProxy,
436-
WorkerPoolDaemon,
437483
)
438484

439485
client = DaemonClient()
440486
if not client.status().get("success"):
441487
safe_print(" ⚙️ Starting Daemon...")
442-
WorkerPoolDaemon().start(daemonize=True)
443-
time.sleep(2)
488+
if not ensure_daemon_running():
489+
return False
444490
except ImportError:
445491
safe_print(" ❌ Daemon modules missing.")
446492
return False
@@ -545,7 +591,7 @@ def chaos_test_3_framework_battle_royale():
545591

546592
# 1. Connect to Daemon and measure startup
547593
try:
548-
from omnipkg.isolation.worker_daemon import DaemonClient, WorkerPoolDaemon
594+
from omnipkg.isolation.worker_daemon import DaemonClient
549595
from concurrent.futures import as_completed
550596
import numpy as np
551597

@@ -562,8 +608,8 @@ def chaos_test_3_framework_battle_royale():
562608
"numpy==1.24.3",
563609
"numpy==2.3.5",
564610
]
565-
WorkerPoolDaemon(warmup_specs=vip_specs).start(daemonize=True)
566-
time.sleep(3)
611+
if not ensure_daemon_running(warmup_specs=vip_specs):
612+
return False
567613
daemon_start = time.perf_counter()
568614
client = DaemonClient()
569615
daemon_connect_time = (time.perf_counter() - daemon_start) * 1000
@@ -656,7 +702,7 @@ def execute_fighter(name, spec, code):
656702

657703
# 1. Connect to Daemon
658704
try:
659-
from omnipkg.isolation.worker_daemon import DaemonClient, WorkerPoolDaemon
705+
from omnipkg.isolation.worker_daemon import DaemonClient
660706

661707
client = DaemonClient()
662708
if not client.status().get("success"):
@@ -668,7 +714,8 @@ def execute_fighter(name, spec, code):
668714
"numpy==1.24.3",
669715
"numpy==2.3.5",
670716
]
671-
WorkerPoolDaemon(warmup_specs=vip_specs).start(daemonize=True)
717+
if not ensure_daemon_running(warmup_specs=vip_specs):
718+
return False
672719
time.sleep(3) # Give TF time to boot (it's heavy)
673720

674721
except ImportError:
@@ -894,7 +941,7 @@ def chaos_test_5_race_condition_roulette():
894941
safe_print("╚══════════════════════════════════════════════════════════════╝\n")
895942

896943
import numpy as np
897-
from omnipkg.isolation.worker_daemon import DaemonClient, WorkerPoolDaemon
944+
from omnipkg.isolation.worker_daemon import DaemonClient
898945

899946
results = {}
900947
versions = ["numpy==1.24.3", "numpy==1.26.4", "numpy==2.3.5"]
@@ -910,9 +957,8 @@ def chaos_test_5_race_condition_roulette():
910957
client = DaemonClient()
911958
if not client.status().get("success"):
912959
safe_print(" ❌ Daemon not running! Starting...")
913-
WorkerPoolDaemon().start(daemonize=True)
914-
time.sleep(2)
915-
960+
if not ensure_daemon_running():
961+
return False
916962
warmup_data = np.random.rand(500, 500).astype(np.float64) # same size as benchmark
917963
for spec in versions:
918964
t_start = time.perf_counter()
@@ -1374,12 +1420,8 @@ def chaos_test_11_tensorflow_resurrection():
13741420
stderr=subprocess.DEVNULL,
13751421
)
13761422
time.sleep(1)
1377-
subprocess.run(
1378-
["8pkg", "daemon", "start"],
1379-
stdout=subprocess.DEVNULL,
1380-
stderr=subprocess.DEVNULL,
1381-
)
1382-
1423+
if not ensure_daemon_running():
1424+
return False
13831425
client = DaemonClient()
13841426
for unused in range(10):
13851427
time.sleep(0.5)
@@ -1442,12 +1484,8 @@ def chaos_test_11_tensorflow_resurrection():
14421484
["8pkg", "daemon", "stop"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
14431485
)
14441486
time.sleep(1)
1445-
subprocess.run(
1446-
["8pkg", "daemon", "start"],
1447-
stdout=subprocess.DEVNULL,
1448-
stderr=subprocess.DEVNULL,
1449-
)
1450-
time.sleep(2)
1487+
if not ensure_daemon_running():
1488+
return False
14511489
client = DaemonClient() # Reconnect
14521490

14531491
safe_print(" 🐢 STEP 1: Sequential Spawn (One by one)...")
@@ -1475,12 +1513,8 @@ def chaos_test_11_tensorflow_resurrection():
14751513
["8pkg", "daemon", "stop"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
14761514
)
14771515
time.sleep(1)
1478-
subprocess.run(
1479-
["8pkg", "daemon", "start"],
1480-
stdout=subprocess.DEVNULL,
1481-
stderr=subprocess.DEVNULL,
1482-
)
1483-
time.sleep(2)
1516+
if not ensure_daemon_running():
1517+
return False
14841518
client = DaemonClient() # Reconnect
14851519

14861520
safe_print(" 🚀 STEP 2: Concurrent Spawn (All at once)...")
@@ -1609,7 +1643,6 @@ def chaos_test_12_jax_vs_torch_mortal_kombat():
16091643
from omnipkg.isolation.worker_daemon import (
16101644
DaemonClient,
16111645
DaemonProxy,
1612-
WorkerPoolDaemon,
16131646
)
16141647

16151648
client = DaemonClient()
@@ -1618,7 +1651,8 @@ def chaos_test_12_jax_vs_torch_mortal_kombat():
16181651
status = client.status()
16191652
if not status.get("success"):
16201653
safe_print(" ⚠️ Daemon not found. Summoning Daemon...")
1621-
WorkerPoolDaemon().start(daemonize=True)
1654+
if not ensure_daemon_running():
1655+
return False
16221656
time.sleep(1) # Wait for socket
16231657

16241658
except ImportError:
@@ -1784,12 +1818,9 @@ def chaos_test_13_pytorch_lightning_storm():
17841818
status = client.status()
17851819
if not status.get("success"):
17861820
safe_print(" ⚙️ Starting daemon...")
1787-
from omnipkg.isolation.worker_daemon import WorkerPoolDaemon
1788-
1789-
daemon = WorkerPoolDaemon()
1790-
daemon.start(daemonize=True)
1791-
time.sleep(1)
17921821

1822+
if not ensure_daemon_running():
1823+
return False
17931824
except ImportError:
17941825
safe_print(" ❌ Daemon not available, falling back to legacy workers")
17951826
return chaos_test_13_pytorch_lightning_storm()
@@ -2022,13 +2053,13 @@ def chaos_test_14_circular_dependency_hell():
20222053
safe_print(" 🔥 Connecting to worker daemon...")
20232054

20242055
try:
2025-
from omnipkg.isolation.worker_daemon import DaemonClient, DaemonProxy, WorkerPoolDaemon
2056+
from omnipkg.isolation.worker_daemon import DaemonClient, DaemonProxy
20262057

20272058
client = DaemonClient()
20282059
if not client.status().get("success"):
20292060
safe_print(" ⚙️ Daemon not found, starting it...")
2030-
WorkerPoolDaemon().start(daemonize=True)
2031-
time.sleep(2)
2061+
if not ensure_daemon_running():
2062+
return False
20322063
except ImportError:
20332064
safe_print(" ❌ FATAL: Daemon components not found. Skipping test.")
20342065
return
@@ -2322,16 +2353,14 @@ def chaos_test_15_isolation_strategy_benchmark():
23222353
from omnipkg.isolation.worker_daemon import (
23232354
DaemonClient,
23242355
DaemonProxy,
2325-
WorkerPoolDaemon,
23262356
)
23272357

23282358
# Ensure daemon is up
23292359
client = DaemonClient()
23302360
if not client.status().get("success"):
23312361
safe_print(" ⚙️ Starting Daemon...")
2332-
WorkerPoolDaemon().start(daemonize=True)
2333-
time.sleep(2)
2334-
2362+
if not ensure_daemon_running():
2363+
return False
23352364
start = time.perf_counter()
23362365
success_count = 0
23372366

@@ -2578,7 +2607,7 @@ def chaos_test_17_triple_python_multiverse():
25782607

25792608
# Initialize daemon
25802609
try:
2581-
from omnipkg.isolation.worker_daemon import DaemonClient, WorkerPoolDaemon
2610+
from omnipkg.isolation.worker_daemon import DaemonClient
25822611
import numpy as np
25832612

25842613
client = DaemonClient()
@@ -3161,7 +3190,6 @@ def chaos_test_18_worker_pool_drag_race():
31613190
from omnipkg.isolation.worker_daemon import (
31623191
DaemonClient,
31633192
DaemonProxy,
3164-
WorkerPoolDaemon,
31653193
)
31663194

31673195
client = DaemonClient()
@@ -3174,7 +3202,8 @@ def chaos_test_18_worker_pool_drag_race():
31743202
"numpy==1.24.3",
31753203
"numpy==1.26.4",
31763204
]
3177-
WorkerPoolDaemon(warmup_specs=vip_specs).start(daemonize=True)
3205+
if not ensure_daemon_running(warmup_specs=vip_specs):
3206+
return False
31783207
time.sleep(2) # Give it a moment to boot the fleet
31793208
except ImportError:
31803209
return False
@@ -3381,10 +3410,8 @@ def chaos_test_20_gpu_resident_pipeline():
33813410
client = DaemonClient()
33823411
if not client.status().get("success"):
33833412
safe_print(" ⚙️ Starting daemon...")
3384-
subprocess.run(
3385-
[sys.executable, "-m", "omnipkg.isolation.worker_daemon", "start"]
3386-
)
3387-
time.sleep(2)
3413+
if not ensure_daemon_running():
3414+
return False
33883415
except ImportError as e:
33893416
safe_print(f" ❌ Failed to import daemon client: {e}")
33903417
return False

0 commit comments

Comments
 (0)