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

Function TestGetDeploymentWorkspaceAgentStats

coderd/database/querier_test.go:43–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41)
42
43func TestGetDeploymentWorkspaceAgentStats(t *testing.T) {
44 t.Parallel()
45 if testing.Short() {
46 t.SkipNow()
47 }
48 t.Run("Aggregates", func(t *testing.T) {
49 t.Parallel()
50 sqlDB := testSQLDB(t)
51 err := migrations.Up(sqlDB)
52 require.NoError(t, err)
53 db := database.New(sqlDB)
54 ctx := context.Background()
55 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
56 TxBytes: 1,
57 RxBytes: 1,
58 ConnectionMedianLatencyMS: 1,
59 SessionCountVSCode: 1,
60 })
61 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
62 TxBytes: 1,
63 RxBytes: 1,
64 ConnectionMedianLatencyMS: 2,
65 SessionCountVSCode: 1,
66 })
67 stats, err := db.GetDeploymentWorkspaceAgentStats(ctx, dbtime.Now().Add(-time.Hour))
68 require.NoError(t, err)
69
70 require.Equal(t, int64(2), stats.WorkspaceTxBytes)
71 require.Equal(t, int64(2), stats.WorkspaceRxBytes)
72 require.Equal(t, 1.5, stats.WorkspaceConnectionLatency50)
73 require.Equal(t, 1.95, stats.WorkspaceConnectionLatency95)
74 require.Equal(t, int64(2), stats.SessionCountVSCode)
75 })
76
77 t.Run("GroupsByAgentID", func(t *testing.T) {
78 t.Parallel()
79
80 sqlDB := testSQLDB(t)
81 err := migrations.Up(sqlDB)
82 require.NoError(t, err)
83 db := database.New(sqlDB)
84 ctx := context.Background()
85 agentID := uuid.New()
86 insertTime := dbtime.Now()
87 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
88 CreatedAt: insertTime.Add(-time.Second),
89 AgentID: agentID,
90 TxBytes: 1,
91 RxBytes: 1,
92 ConnectionMedianLatencyMS: 1,
93 SessionCountVSCode: 1,
94 })
95 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
96 // Ensure this stat is newer!
97 CreatedAt: insertTime,
98 AgentID: agentID,
99 TxBytes: 1,
100 RxBytes: 1,

Callers

nothing calls this directly

Calls 11

UpFunction · 0.92
NewFunction · 0.92
WorkspaceAgentStatFunction · 0.92
NowFunction · 0.92
SkipNowMethod · 0.80
testSQLDBFunction · 0.70
RunMethod · 0.65
AddMethod · 0.65
NewMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected