MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestResolveWorkerProfileSizing

Function TestResolveWorkerProfileSizing

controlplane/worker_profile_test.go:28–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestResolveWorkerProfileSizing(t *testing.T) {
29 cp := newSizingTestCP()
30 tests := []struct {
31 name string
32 opts map[string]string
33 wantNil bool // expect the default (nil) profile — matches the neutral warm pool
34 wantKey string // CPU|Memory (only when !wantNil)
35 wantTTL time.Duration
36 wantErr bool
37 wantWarn bool
38 }{
39 {name: "no opts -> default (nil)", opts: map[string]string{}, wantNil: true},
40 {name: "unrelated opts -> default (nil)", opts: map[string]string{"search_path": "analytics.public"}, wantNil: true},
41 {name: "client cpu+mem", opts: map[string]string{gucWorkerCPU: "4", gucWorkerMemory: "32Gi"}, wantKey: "4|32Gi", wantTTL: defaultWorkerTTL},
42 {name: "client ttl only -> concrete w/ default size", opts: map[string]string{gucWorkerTTL: "5m"}, wantKey: "8|16Gi", wantTTL: 5 * time.Minute},
43 {name: "cpu over max -> clamp+warn", opts: map[string]string{gucWorkerCPU: "64"}, wantKey: "16|16Gi", wantTTL: defaultWorkerTTL, wantWarn: true},
44 {name: "mem under min -> clamp+warn", opts: map[string]string{gucWorkerMemory: "1Gi"}, wantKey: "8|4Gi", wantTTL: defaultWorkerTTL, wantWarn: true},
45 {name: "ttl over max -> clamp+warn", opts: map[string]string{gucWorkerTTL: "24h"}, wantKey: "8|16Gi", wantTTL: time.Hour, wantWarn: true},
46 {name: "cpu normalized", opts: map[string]string{gucWorkerCPU: "4000m"}, wantKey: "4|16Gi", wantTTL: defaultWorkerTTL},
47 {name: "zero cpu -> error", opts: map[string]string{gucWorkerCPU: "0"}, wantErr: true},
48 {name: "bad mem -> error", opts: map[string]string{gucWorkerMemory: "lots"}, wantErr: true},
49 {name: "bad ttl -> error", opts: map[string]string{gucWorkerTTL: "soon"}, wantErr: true},
50 {name: "negative ttl -> error", opts: map[string]string{gucWorkerTTL: "-5m"}, wantErr: true},
51 }
52
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 got, warns, orgApplied, err := cp.resolveWorkerProfile(tt.opts, noOrgDefaults)
56 if orgApplied {
57 t.Fatal("orgApplied must be false without org defaults")
58 }
59 if tt.wantErr {
60 if err == nil {
61 t.Fatalf("expected error, got profile=%v", got)
62 }
63 return
64 }
65 if err != nil {
66 t.Fatalf("unexpected error: %v", err)
67 }
68 if tt.wantNil {
69 if got != nil {
70 t.Fatalf("expected nil (default) profile, got %s", got.MatchKey())
71 }
72 return
73 }
74 if got == nil {
75 t.Fatalf("expected concrete profile %q, got nil", tt.wantKey)
76 }
77 if got.MatchKey() != tt.wantKey {
78 t.Fatalf("MatchKey = %q, want %q", got.MatchKey(), tt.wantKey)
79 }
80 if got.TTL != tt.wantTTL {
81 t.Fatalf("TTL = %s, want %s", got.TTL, tt.wantTTL)
82 }
83 if tt.wantWarn && len(warns) == 0 {
84 t.Fatal("expected a clamp warning, got none")
85 }

Callers

nothing calls this directly

Calls 4

newSizingTestCPFunction · 0.85
resolveWorkerProfileMethod · 0.80
MatchKeyMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected