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

Function TestGetDeploymentWorkspaceAgentUsageStats

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

Source from the content-addressed store, hash-verified

113}
114
115func TestGetDeploymentWorkspaceAgentUsageStats(t *testing.T) {
116 t.Parallel()
117
118 t.Run("Aggregates", func(t *testing.T) {
119 t.Parallel()
120
121 db, _ := dbtestutil.NewDB(t)
122 authz := rbac.NewAuthorizer(prometheus.NewRegistry())
123 db = dbauthz.New(db, authz, slogtest.Make(t, &slogtest.Options{}), coderdtest.AccessControlStorePointer())
124 ctx := context.Background()
125 agentID := uuid.New()
126 // Since the queries exclude the current minute
127 insertTime := dbtime.Now().Add(-time.Minute)
128
129 // Old stats
130 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
131 CreatedAt: insertTime.Add(-time.Minute),
132 AgentID: agentID,
133 TxBytes: 1,
134 RxBytes: 1,
135 ConnectionMedianLatencyMS: 1,
136 // Should be ignored
137 SessionCountSSH: 4,
138 SessionCountVSCode: 3,
139 })
140 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
141 CreatedAt: insertTime.Add(-time.Minute),
142 AgentID: agentID,
143 SessionCountVSCode: 1,
144 Usage: true,
145 })
146 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
147 CreatedAt: insertTime.Add(-time.Minute),
148 AgentID: agentID,
149 SessionCountReconnectingPTY: 1,
150 Usage: true,
151 })
152
153 // Latest stats
154 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
155 CreatedAt: insertTime,
156 AgentID: agentID,
157 TxBytes: 1,
158 RxBytes: 1,
159 ConnectionMedianLatencyMS: 2,
160 // Should be ignored
161 SessionCountSSH: 3,
162 SessionCountVSCode: 1,
163 })
164 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
165 CreatedAt: insertTime,
166 AgentID: agentID,
167 SessionCountVSCode: 1,
168 Usage: true,
169 })
170 dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
171 CreatedAt: insertTime,
172 AgentID: agentID,

Callers

nothing calls this directly

Calls 11

NewDBFunction · 0.92
NewAuthorizerFunction · 0.92
NewFunction · 0.92
NowFunction · 0.92
WorkspaceAgentStatFunction · 0.92
RunMethod · 0.65
NewMethod · 0.65
AddMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected