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

Function TestStatsCollector

coderd/workspaceapps/stats_test.go:58–345  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestStatsCollector(t *testing.T) {
59 t.Parallel()
60
61 rollupUUID := uuid.New()
62 rollupUUID2 := uuid.New()
63 someUUID := uuid.New()
64
65 rollupWindow := time.Minute
66 start := dbtime.Now().Truncate(time.Minute).UTC()
67 end := start.Add(10 * time.Second)
68
69 tests := []struct {
70 name string
71 flushIncrement time.Duration
72 flushCount int
73 stats []workspaceapps.StatsReport
74 want []workspaceapps.StatsReport
75 }{
76 {
77 name: "Single stat rolled up and reported once",
78 flushIncrement: 2*rollupWindow + time.Second,
79 flushCount: 10, // Only reported once.
80 stats: []workspaceapps.StatsReport{
81 {
82 SessionID: rollupUUID,
83 SessionStartedAt: start,
84 SessionEndedAt: end,
85 Requests: 1,
86 },
87 },
88 want: []workspaceapps.StatsReport{
89 {
90 SessionID: rollupUUID,
91 SessionStartedAt: start,
92 SessionEndedAt: start.Add(rollupWindow),
93 Requests: 1,
94 },
95 },
96 },
97 {
98 name: "Two unique stat rolled up",
99 flushIncrement: 2*rollupWindow + time.Second,
100 flushCount: 10, // Only reported once.
101 stats: []workspaceapps.StatsReport{
102 {
103 AccessMethod: workspaceapps.AccessMethodPath,
104 SlugOrPort: "code-server",
105 SessionID: rollupUUID,
106 SessionStartedAt: start,
107 SessionEndedAt: end,
108 Requests: 1,
109 },
110 {
111 AccessMethod: workspaceapps.AccessMethodTerminal,
112 SessionID: rollupUUID2,
113 SessionStartedAt: start,
114 SessionEndedAt: end,
115 Requests: 1,

Callers

nothing calls this directly

Calls 11

CollectMethod · 0.95
statsMethod · 0.95
NowFunction · 0.92
NewStatsCollectorFunction · 0.92
NewMethod · 0.65
AddMethod · 0.65
RunMethod · 0.65
StoreMethod · 0.45
LoadMethod · 0.45
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected