MCPcopy Index your code
hub / github.com/coder/coder / TestStreamStateCollector

Function TestStreamStateCollector

coderd/x/chatd/streamcollector_internal_test.go:22–137  ·  view source on GitHub ↗

TestStreamStateCollector exercises the four gauges emitted by streamStateCollector against representative map states.

(t *testing.T)

Source from the content-addressed store, hash-verified

20// TestStreamStateCollector exercises the four gauges emitted by
21// streamStateCollector against representative map states.
22func TestStreamStateCollector(t *testing.T) {
23 t.Parallel()
24
25 t.Run("EmptyMap", func(t *testing.T) {
26 t.Parallel()
27
28 reg := prometheus.NewRegistry()
29 server := &Server{}
30 reg.MustRegister(&streamStateCollector{server: server})
31
32 assertGauges(t, reg, gaugeExpectations{
33 active: 0,
34 bufferMax: 0,
35 bufferTotal: 0,
36 subscribers: 0,
37 })
38 })
39
40 t.Run("PopulatedMap", func(t *testing.T) {
41 t.Parallel()
42
43 reg := prometheus.NewRegistry()
44 server := &Server{}
45
46 server.chatStreams.Store(uuid.New(), &chatStreamState{
47 buffer: make([]bufferedStreamPart, 10),
48 subscribers: newSubscribers(t, 2),
49 })
50 server.chatStreams.Store(uuid.New(), &chatStreamState{
51 buffer: make([]bufferedStreamPart, 25),
52 subscribers: map[uuid.UUID]chan codersdk.ChatStreamEvent{},
53 })
54 server.chatStreams.Store(uuid.New(), &chatStreamState{
55 buffer: nil,
56 subscribers: newSubscribers(t, 1),
57 })
58
59 reg.MustRegister(&streamStateCollector{server: server})
60
61 assertGauges(t, reg, gaugeExpectations{
62 active: 3,
63 bufferMax: 25,
64 bufferTotal: 35,
65 subscribers: 3,
66 })
67 })
68
69 t.Run("SkipsWrongType", func(t *testing.T) {
70 t.Parallel()
71
72 reg := prometheus.NewRegistry()
73 server := &Server{}
74
75 server.chatStreams.Store(uuid.New(), "garbage")
76 server.chatStreams.Store(uuid.New(), &chatStreamState{
77 buffer: make([]bufferedStreamPart, 5),
78 subscribers: newSubscribers(t, 1),
79 })

Callers

nothing calls this directly

Calls 12

CollectMethod · 0.95
ContextFunction · 0.92
SoftTryReceiveFunction · 0.92
assertGaugesFunction · 0.85
newSubscribersFunction · 0.85
GoMethod · 0.80
RunMethod · 0.65
NewMethod · 0.65
WaitMethod · 0.65
StoreMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected