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

Function TestComputeConnectionUsage

controlplane/compute_meter_test.go:12–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestComputeConnectionUsage(t *testing.T) {
13 tests := []struct {
14 name string
15 millicores int64
16 mib int64
17 dur time.Duration
18 wantCPU int64 // milli-cpu-seconds
19 wantMem int64 // mib-seconds
20 }{
21 {
22 // 8 vCPU / 16 GiB held 9.2s → ceil 10 → 80 vCPU-s, 160 GiB-s.
23 name: "8cpu_16gib_9.2s", millicores: 8000, mib: 16 * 1024, dur: 9200 * time.Millisecond,
24 wantCPU: 8000 * 10, wantMem: 16 * 1024 * 10,
25 },
26 {
27 // Exactly 10s, no ceil bump.
28 name: "8cpu_64gib_10s", millicores: 8000, mib: 64 * 1024, dur: 10 * time.Second,
29 wantCPU: 8000 * 10, wantMem: 64 * 1024 * 10,
30 },
31 {
32 // Sub-second connection still bills one whole second.
33 name: "2cpu_4gib_0.3s", millicores: 2000, mib: 4 * 1024, dur: 300 * time.Millisecond,
34 wantCPU: 2000 * 1, wantMem: 4 * 1024 * 1,
35 },
36 {
37 // Fractional core (500m) — no truncation thanks to millicore math.
38 name: "500m_512Mi_3s", millicores: 500, mib: 512, dur: 3 * time.Second,
39 wantCPU: 500 * 3, wantMem: 512 * 3,
40 },
41 {
42 // Unknown worker size → skipped.
43 name: "unknown_size", millicores: 0, mib: 0, dur: 30 * time.Second,
44 wantCPU: 0, wantMem: 0,
45 },
46 }
47 for _, tt := range tests {
48 t.Run(tt.name, func(t *testing.T) {
49 gotCPU, gotMem := computeConnectionUsage(tt.millicores, tt.mib, tt.dur)
50 if gotCPU != tt.wantCPU || gotMem != tt.wantMem {
51 t.Fatalf("computeConnectionUsage(%d,%d,%v) = (%d,%d), want (%d,%d)",
52 tt.millicores, tt.mib, tt.dur, gotCPU, gotMem, tt.wantCPU, tt.wantMem)
53 }
54 })
55 }
56}
57
58// keyA is the billing key most tests share: orgA's informational team,
59// standard source, an 8-vCPU/16-GiB worker.

Callers

nothing calls this directly

Calls 2

computeConnectionUsageFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected