TestOrgReservedPoolWorkerCount covers the per-org worker count surfaced to the admin Overview load bars: it counts this org's cap-counting (Hot) workers, excludes hot-idle (parked, not against cap), and ignores workers assigned to a different org sharing the pool.
(t *testing.T)
| 100 | // workers, excludes hot-idle (parked, not against cap), and ignores workers |
| 101 | // assigned to a different org sharing the pool. |
| 102 | func TestOrgReservedPoolWorkerCount(t *testing.T) { |
| 103 | shared, _ := newTestK8sPool(t, 10) |
| 104 | |
| 105 | mk := func(id int, org string, lc WorkerLifecycleState) { |
| 106 | w := &ManagedWorker{ID: id, activeSessions: 1, done: make(chan struct{})} |
| 107 | w.SetOwnerCPInstanceID(shared.cpInstanceID) |
| 108 | w.SetOwnerEpoch(1) |
| 109 | if err := w.SetSharedState(SharedWorkerState{ |
| 110 | Lifecycle: lc, |
| 111 | Assignment: &WorkerAssignment{OrgID: org}, |
| 112 | }); err != nil { |
| 113 | t.Fatalf("SetSharedState(%d): %v", id, err) |
| 114 | } |
| 115 | shared.workers[id] = w |
| 116 | } |
| 117 | // Two Hot workers for analytics (counted), one analytics hot-idle (excluded), |
| 118 | // one Hot worker for another org (excluded). |
| 119 | mk(1, "analytics", WorkerLifecycleHot) |
| 120 | mk(2, "analytics", WorkerLifecycleHot) |
| 121 | mk(3, "analytics", WorkerLifecycleHotIdle) |
| 122 | mk(4, "other", WorkerLifecycleHot) |
| 123 | |
| 124 | pool := NewOrgReservedPool(shared, "analytics", 5, shared.workerImage, nil) |
| 125 | if got := pool.WorkerCount(); got != 2 { |
| 126 | t.Fatalf("WorkerCount() = %d, want 2 (two Hot analytics workers; hot-idle + other-org excluded)", got) |
| 127 | } |
| 128 | |
| 129 | // Empty org → 0, never negative. |
| 130 | empty := NewOrgReservedPool(shared, "nobody", 5, shared.workerImage, nil) |
| 131 | if got := empty.WorkerCount(); got != 0 { |
| 132 | t.Fatalf("WorkerCount() for org with no workers = %d, want 0", got) |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | func TestOrgReservedPoolReleaseWorkerTransitionsToHotIdleOnLastSession(t *testing.T) { |
| 137 | shared, _ := newTestK8sPool(t, 5) |
nothing calls this directly
no test coverage detected