package tests import ( "runtime" "testing" ) // TestResolveCPUWorkers covers the three parse branches: empty/"all" // falls back to NumCPU, a valid integer is used verbatim, and garbage // also falls back to NumCPU rather than returning zero. Zero workers // would make stress-ng a no-op and silently defeat Burn's CPU load. func TestResolveCPUWorkers(t *testing.T) { np := runtime.NumCPU() cases := []struct { name string in string want int }{ {"empty defaults to NumCPU", "", np}, {"all defaults to NumCPU", "all", np}, {"ALL is case-insensitive", "ALL", np}, {"explicit integer", "3", 3}, {"negative falls back", "-1", np}, {"zero falls back", "0", np}, {"garbage falls back", "lots", np}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { if got := resolveCPUWorkers(tc.in); got != tc.want { t.Errorf("resolveCPUWorkers(%q) = %d, want %d", tc.in, got, tc.want) } }) } } // TestClampMemPct ensures the mem_pct knob never drives the memory // burner into OOM territory (upper clamp) or into uselessness (lower // clamp). Zero is treated as "use default 50" so a missing knob in an // older orchestrator's claim response doesn't collapse the workload. func TestClampMemPct(t *testing.T) { cases := []struct { in, want int }{ {0, 50}, // default {-10, 50}, // negative treated as default {5, 10}, // below lower band → clamp up {10, 10}, {50, 50}, {90, 90}, {95, 90}, // above upper band → clamp down {1000, 90}, } for _, tc := range cases { if got := clampMemPct(tc.in); got != tc.want { t.Errorf("clampMemPct(%d) = %d, want %d", tc.in, got, tc.want) } } }