Files
pulse/internal/monitoring/monitor_start_workers_test.go
T
rcourtman 3fe1f7f181 Quiet the broadcast ticker and allow larger poll worker pools
The broadcast ticker logged seven fields at Info level every tick and
built a full state snapshot to do it, before checking whether any
WebSocket subscriber existed. An idle server paid a snapshot copy plus
roughly 8600 log lines a day for nothing. The log is now Debug and both
the log and the snapshot build sit behind the subscriber check.

The poll task worker pool was also fixed at ten workers no matter how
many instances an estate monitors. POLL_TASK_WORKERS now overrides the
count and the cap, bounded at 128, following the existing env knob
pattern. Behavior without the variable is unchanged.

Contract-Neutral: operational log demotion and an opt-in worker pool env knob, no monitoring or agent-lifecycle contract semantics change
2026-08-16 13:24:08 +01:00

47 lines
1.3 KiB
Go

package monitoring
import "testing"
func TestResolveTaskWorkerCountDefaultClamp(t *testing.T) {
t.Setenv("POLL_TASK_WORKERS", "")
cases := []struct {
name string
in int
want int
}{
{name: "zero clients floors to one worker", in: 0, want: 1},
{name: "negative floors to one worker", in: -3, want: 1},
{name: "small estates keep their count", in: 4, want: 4},
{name: "large estates cap at ten", in: 40, want: 10},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := resolveTaskWorkerCount(tc.in); got != tc.want {
t.Fatalf("resolveTaskWorkerCount(%d) = %d, want %d", tc.in, got, tc.want)
}
})
}
}
func TestResolveTaskWorkerCountEnvOverride(t *testing.T) {
t.Setenv("POLL_TASK_WORKERS", "24")
if got := resolveTaskWorkerCount(3); got != 24 {
t.Fatalf("override ignored: got %d, want 24", got)
}
}
func TestResolveTaskWorkerCountEnvOverrideCeiling(t *testing.T) {
t.Setenv("POLL_TASK_WORKERS", "5000")
if got := resolveTaskWorkerCount(3); got != 128 {
t.Fatalf("override ceiling not applied: got %d, want 128", got)
}
}
func TestResolveTaskWorkerCountInvalidOverrideFallsBack(t *testing.T) {
t.Setenv("POLL_TASK_WORKERS", "not-a-number")
if got := resolveTaskWorkerCount(40); got != 10 {
t.Fatalf("invalid override should fall back to default clamp: got %d, want 10", got)
}
}