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

Function TestDeploymentInsights

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

Source from the content-addressed store, hash-verified

40)
41
42func TestDeploymentInsights(t *testing.T) {
43 t.Parallel()
44
45 clientTz, err := time.LoadLocation("America/Chicago")
46 require.NoError(t, err)
47
48 db, ps := dbtestutil.NewDB(t, dbtestutil.WithDumpOnFailure())
49 logger := testutil.Logger(t)
50 rollupEvents := make(chan dbrollup.Event)
51 statsInterval := 500 * time.Millisecond
52 // Speed up the test by controlling batch size and interval.
53 batcher, closeBatcher, err := workspacestats.NewBatcher(context.Background(),
54 workspacestats.BatcherWithLogger(logger.Named("batcher").Leveled(slog.LevelDebug)),
55 workspacestats.BatcherWithStore(db),
56 workspacestats.BatcherWithBatchSize(1),
57 workspacestats.BatcherWithInterval(statsInterval),
58 )
59 require.NoError(t, err)
60 defer closeBatcher()
61 client := coderdtest.New(t, &coderdtest.Options{
62 Database: db,
63 Pubsub: ps,
64 Logger: &logger,
65 IncludeProvisionerDaemon: true,
66 AgentStatsRefreshInterval: statsInterval,
67 StatsBatcher: batcher,
68 DatabaseRolluper: dbrollup.New(
69 logger.Named("dbrollup").Leveled(slog.LevelDebug),
70 db,
71 dbrollup.WithInterval(statsInterval/2),
72 dbrollup.WithEventChannel(rollupEvents),
73 ),
74 })
75
76 user := coderdtest.CreateFirstUser(t, client)
77 authToken := uuid.NewString()
78 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
79 Parse: echo.ParseComplete,
80 ProvisionPlan: echo.PlanComplete,
81 ProvisionGraph: echo.ProvisionGraphWithAgent(authToken),
82 })
83 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
84 require.Empty(t, template.BuildTimeStats[codersdk.WorkspaceTransitionStart])
85
86 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
87 workspace := coderdtest.CreateWorkspace(t, client, template.ID)
88 coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
89
90 ctx := testutil.Context(t, testutil.WaitSuperLong)
91
92 // Pre-check, no permission issues.
93 daus, err := client.DeploymentDAUs(ctx, codersdk.TimezoneOffsetHour(clientTz))
94 require.NoError(t, err)
95
96 _ = agenttest.New(t, client.URL, authToken)
97 resources := coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
98
99 conn, err := workspacesdk.New(client).

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
WithDumpOnFailureFunction · 0.92
LoggerFunction · 0.92
NewBatcherFunction · 0.92
BatcherWithLoggerFunction · 0.92
BatcherWithStoreFunction · 0.92
BatcherWithBatchSizeFunction · 0.92
BatcherWithIntervalFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
WithIntervalFunction · 0.92
WithEventChannelFunction · 0.92

Tested by

no test coverage detected