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

Function TestUserLatencyInsights

coderd/insights_test.go:243–340  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

241}
242
243func TestUserLatencyInsights(t *testing.T) {
244 t.Parallel()
245
246 db, ps := dbtestutil.NewDB(t)
247 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
248 client := coderdtest.New(t, &coderdtest.Options{
249 Database: db,
250 Pubsub: ps,
251 Logger: &logger,
252 IncludeProvisionerDaemon: true,
253 AgentStatsRefreshInterval: time.Millisecond * 50,
254 DatabaseRolluper: dbrollup.New(
255 logger.Named("dbrollup"),
256 db,
257 dbrollup.WithInterval(time.Millisecond*100),
258 ),
259 })
260
261 // Create two users, one that will appear in the report and another that
262 // won't (due to not having/using a workspace).
263 user := coderdtest.CreateFirstUser(t, client)
264 _, _ = coderdtest.CreateAnotherUser(t, client, user.OrganizationID)
265 authToken := uuid.NewString()
266 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
267 Parse: echo.ParseComplete,
268 ProvisionPlan: echo.PlanComplete,
269 ProvisionGraph: echo.ProvisionGraphWithAgent(authToken),
270 })
271 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
272 require.Empty(t, template.BuildTimeStats[codersdk.WorkspaceTransitionStart])
273
274 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
275 workspace := coderdtest.CreateWorkspace(t, client, template.ID)
276 coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
277
278 // Start an agent so that we can generate stats.
279 _ = agenttest.New(t, client.URL, authToken)
280 resources := coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
281
282 // Start must be at the beginning of the day, initialize it early in case
283 // the day changes so that we get the relevant stats faster.
284 y, m, d := time.Now().UTC().Date()
285 today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
286
287 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
288 defer cancel()
289
290 // Connect to the agent to generate usage/latency stats.
291 conn, err := workspacesdk.New(client).
292 DialAgent(ctx, resources[0].Agents[0].ID, &workspacesdk.DialAgentOptions{
293 Logger: logger.Named("client"),
294 })
295 require.NoError(t, err)
296 defer conn.Close()
297
298 sshConn, err := conn.SSHClient(ctx)
299 require.NoError(t, err)
300 defer sshConn.Close()

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
WithIntervalFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
ProvisionGraphWithAgentFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92

Tested by

no test coverage detected