(t *testing.T)
| 143 | } |
| 144 | |
| 145 | func TestUserActivityInsights_SanityCheck(t *testing.T) { |
| 146 | t.Parallel() |
| 147 | |
| 148 | db, ps := dbtestutil.NewDB(t) |
| 149 | logger := testutil.Logger(t) |
| 150 | client := coderdtest.New(t, &coderdtest.Options{ |
| 151 | Database: db, |
| 152 | Pubsub: ps, |
| 153 | Logger: &logger, |
| 154 | IncludeProvisionerDaemon: true, |
| 155 | AgentStatsRefreshInterval: time.Millisecond * 100, |
| 156 | DatabaseRolluper: dbrollup.New( |
| 157 | logger.Named("dbrollup"), |
| 158 | db, |
| 159 | dbrollup.WithInterval(time.Millisecond*100), |
| 160 | ), |
| 161 | }) |
| 162 | |
| 163 | // Create two users, one that will appear in the report and another that |
| 164 | // won't (due to not having/using a workspace). |
| 165 | user := coderdtest.CreateFirstUser(t, client) |
| 166 | _, _ = coderdtest.CreateAnotherUser(t, client, user.OrganizationID) |
| 167 | authToken := uuid.NewString() |
| 168 | version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{ |
| 169 | Parse: echo.ParseComplete, |
| 170 | ProvisionPlan: echo.PlanComplete, |
| 171 | ProvisionGraph: echo.ProvisionGraphWithAgent(authToken), |
| 172 | }) |
| 173 | template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) |
| 174 | require.Empty(t, template.BuildTimeStats[codersdk.WorkspaceTransitionStart]) |
| 175 | |
| 176 | coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 177 | workspace := coderdtest.CreateWorkspace(t, client, template.ID) |
| 178 | coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) |
| 179 | |
| 180 | // Start an agent so that we can generate stats. |
| 181 | _ = agenttest.New(t, client.URL, authToken) |
| 182 | resources := coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID) |
| 183 | |
| 184 | // Start must be at the beginning of the day, initialize it early in case |
| 185 | // the day changes so that we get the relevant stats faster. |
| 186 | y, m, d := time.Now().UTC().Date() |
| 187 | today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC) |
| 188 | |
| 189 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong) |
| 190 | defer cancel() |
| 191 | |
| 192 | // Connect to the agent to generate usage/latency stats. |
| 193 | conn, err := workspacesdk.New(client). |
| 194 | DialAgent(ctx, resources[0].Agents[0].ID, &workspacesdk.DialAgentOptions{ |
| 195 | Logger: logger.Named("client"), |
| 196 | }) |
| 197 | require.NoError(t, err) |
| 198 | defer conn.Close() |
| 199 | |
| 200 | sshConn, err := conn.SSHClient(ctx) |
| 201 | require.NoError(t, err) |
| 202 | defer sshConn.Close() |
nothing calls this directly
no test coverage detected