File size: 1,619 Bytes
0c79003
 
 
 
160d7db
0c79003
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Verify that services run as SEPARATE OS PROCESSES with unique PIDs."""
import sys, time
sys.path.insert(0, "D:/Meta")

from services.orchestrator import ServiceOrchestrator

o = ServiceOrchestrator(
    db_path="D:/Meta/cloud_sre_v2/_test_data/app.db",
    log_dir="D:/Meta/cloud_sre_v2/_test_data/logs",
)
o.start()

print("=" * 60)
print("PROCESS ISOLATION PROOF")
print("=" * 60)

pids = set()
for name, entry in o._processes.items():
    pid = entry["pid"]
    port = entry["port"]
    alive = entry["proc"].poll() is None
    pids.add(pid)
    print(f"  {name:10s}  PID={pid:>6d}  port={port}  alive={alive}")

print(f"\nUnique PIDs: {len(pids)}")
print(f"All different: {len(pids) == 4}")

# Now kill one and show it's really dead
print("\n--- Killing worker (PID={}) ---".format(o._processes["worker"]["pid"]))
o._stop_service("worker")
time.sleep(0.5)

# Try to curl the dead service
import httpx
try:
    r = httpx.get("http://localhost:8003/healthz", timeout=2)
    print(f"Worker healthz: {r.status_code} (should have failed!)")
except httpx.ConnectError:
    print("✅ Worker port 8003: Connection refused (process is DEAD)")

# Restart and show new PID
old_pid = o._processes["worker"]["pid"]
o.restart_service("worker")
new_pid = o._processes["worker"]["pid"]
print(f"\n--- Restarted worker: PID {old_pid} → {new_pid} ---")
print(f"PID changed: {old_pid != new_pid}")

time.sleep(0.5)
try:
    r = httpx.get("http://localhost:8003/healthz", timeout=2)
    print(f"✅ Worker healthz: {r.status_code} (alive with new PID)")
except httpx.ConnectError:
    print("❌ Worker still dead")

o.shutdown()