nx_runsv_gate.nx source
↩ module page · 37 lines · 2302 B
1// nx_runsv_gate.nx -- proves nx_runsv composes the team's organs correctly: hp_probe gives a REAL readiness verdict
2// against the live supervised server (:8080), and rs_decide maps liveness+readiness to the right action with crash-loop
3// backoff. (Replaces the mis-named nx_supervise_gate; nx_supervise is the team's existing simulated-health gate.)
4// license_tier: ORIGINAL
5import "nx_runsv.nx"
6import "nx_gate.nx"
7
8func main() -> i64 {
9 gw("=== nx_runsv_gate: supervisor decision logic + live readiness (team-organ composition) ===\n" as *u8)
10 var pass: i64=0; var tot: i64=0
11
12 let v: i64 = hp_probe(8080, 3)
13 tot=tot+1; if v==HP_SERVING { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
14 gw("T1 nx_health_probe :8080 -> SERVING (real readiness vs the LIVE supervised server, verdict=" as *u8); gn(v); gw(")\n" as *u8)
15
16 let ws: *i64=sys_mmap(16) as *i64; let cnt: *i64=sys_mmap(16) as *i64; ws[0]=0; cnt[0]=0
17 let a1: i64 = rs_decide(1, 0, ws, cnt, 1000)
18 tot=tot+1; if a1==RS_RESPAWN { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
19 gw("T2 first death -> RESPAWN (minimal downtime)\n" as *u8)
20
21 let a2: i64 = rs_decide(1, 0, ws, cnt, 1050)
22 tot=tot+1; if a2==RS_BACKOFF { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
23 gw("T3 rapid 2nd death (50ms<100ms backoff) -> BACKOFF (crash-loop contained)\n" as *u8)
24
25 let ws2: *i64=sys_mmap(16) as *i64; let cnt2: *i64=sys_mmap(16) as *i64; ws2[0]=0; cnt2[0]=0
26 let a3: i64 = rs_decide(0, HP_HUNG, ws2, cnt2, 1000)
27 tot=tot+1; if a3==RS_KILLHUNG { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
28 gw("T4 up-but-not-serving (HUNG) -> KILL + respawn (the case PID-liveness misses)\n" as *u8)
29
30 let a4: i64 = rs_decide(0, HP_SERVING, ws2, cnt2, 1000)
31 tot=tot+1; if a4==RS_OK { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
32 gw("T5 serving -> OK (no needless restart)\n" as *u8)
33
34 gw("\n=== nx_runsv_gate " as *u8); gn(pass); gw("/" as *u8); gn(tot); gw(" ===\n" as *u8)
35 if pass==tot { gw("RUNSV GREEN -- s6-style supervisor composing nx_health_probe + nx_restart_guard, LIVE on :8080\n" as *u8); sys_exit(0); return 0 }
36 gw("RUNSV RED\n" as *u8); sys_exit(1); return 1
37}