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

Function TestCache_DeploymentStats

coderd/metricscache/metricscache_test.go:295–343  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

293}
294
295func TestCache_DeploymentStats(t *testing.T) {
296 t.Parallel()
297
298 var (
299 ctx = testutil.Context(t, testutil.WaitShort)
300 log = testutil.Logger(t)
301 clock = quartz.NewMock(t)
302 )
303
304 tickerTrap := clock.Trap().TickerFunc("metricscache")
305 defer tickerTrap.Close()
306
307 cache, db := newMetricsCache(t, log, clock, metricscache.Intervals{
308 DeploymentStats: time.Minute,
309 }, false)
310
311 err := db.InsertWorkspaceAgentStats(context.Background(), database.InsertWorkspaceAgentStatsParams{
312 ID: []uuid.UUID{uuid.New()},
313 CreatedAt: []time.Time{clock.Now()},
314 WorkspaceID: []uuid.UUID{uuid.New()},
315 UserID: []uuid.UUID{uuid.New()},
316 TemplateID: []uuid.UUID{uuid.New()},
317 AgentID: []uuid.UUID{uuid.New()},
318 ConnectionsByProto: json.RawMessage(`[{}]`),
319
320 RxPackets: []int64{0},
321 RxBytes: []int64{1},
322 TxPackets: []int64{0},
323 TxBytes: []int64{1},
324 ConnectionCount: []int64{1},
325 SessionCountVSCode: []int64{1},
326 SessionCountJetBrains: []int64{0},
327 SessionCountReconnectingPTY: []int64{0},
328 SessionCountSSH: []int64{0},
329 ConnectionMedianLatencyMS: []float64{10},
330 Usage: []bool{false},
331 })
332 require.NoError(t, err)
333
334 // Wait for both ticker functions to be created (template build times and deployment stats)
335 tickerTrap.MustWait(ctx).MustRelease(ctx)
336 tickerTrap.MustWait(ctx).MustRelease(ctx)
337
338 clock.Advance(time.Minute).MustWait(ctx)
339
340 stat, ok := cache.DeploymentStats()
341 require.True(t, ok, "cache should be populated after refresh")
342 require.Equal(t, int64(1), stat.SessionCount.VSCode)
343}

Callers

nothing calls this directly

Calls 8

ContextFunction · 0.92
LoggerFunction · 0.92
newMetricsCacheFunction · 0.85
CloseMethod · 0.65
NewMethod · 0.65
DeploymentStatsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected