Skip to content

Commit 3bc91b5

Browse files
committed
test produce another active user via app usage
1 parent 6fd3d93 commit 3bc91b5

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

coderd/insights_test.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ func TestTemplateInsights(t *testing.T) {
274274
client, _, coderdAPI := coderdtest.NewWithAPI(t, opts)
275275

276276
user := coderdtest.CreateFirstUser(t, client)
277+
_, otherUser := coderdtest.CreateAnotherUser(t, client, user.OrganizationID)
277278
authToken := uuid.NewString()
278279
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
279280
Parse: echo.ParseComplete,
@@ -390,6 +391,20 @@ func TestTemplateInsights(t *testing.T) {
390391
SessionEndedAt: requestStartTime.Add(1 * time.Minute),
391392
Requests: 1,
392393
},
394+
{
395+
// Other use is using users workspace, this will result in an
396+
// additional active user and more time spent in app.
397+
UserID: otherUser.ID,
398+
WorkspaceID: workspace.ID,
399+
AgentID: resources[0].Agents[0].ID,
400+
AccessMethod: workspaceapps.AccessMethodPath,
401+
SlugOrPort: testAppSlug,
402+
SessionID: uuid.New(),
403+
// One minute of usage (rounded up to 5 due to query intervals).
404+
SessionStartedAt: requestStartTime,
405+
SessionEndedAt: requestStartTime.Add(1 * time.Minute),
406+
Requests: 1,
407+
},
393408
{
394409
UserID: user.UserID,
395410
WorkspaceID: workspace.ID,
@@ -482,7 +497,7 @@ func TestTemplateInsights(t *testing.T) {
482497

483498
assert.WithinDuration(t, req.StartTime, resp.Report.StartTime, 0)
484499
assert.WithinDuration(t, req.EndTime, resp.Report.EndTime, 0)
485-
assert.Equal(t, resp.Report.ActiveUsers, int64(1), "want one active user")
500+
assert.Equal(t, int64(2), resp.Report.ActiveUsers, "want two active users")
486501
var gotApps []codersdk.TemplateAppUsage
487502
// Check builtin apps usage.
488503
for _, app := range resp.Report.AppsUsage {
@@ -504,15 +519,15 @@ func TestTemplateInsights(t *testing.T) {
504519
Slug: testAppSlug,
505520
DisplayName: testAppName,
506521
Icon: testAppIcon,
507-
Seconds: 300 + 300, // Two times 5 minutes of usage (actually 1 + 5, but see TODO above).
522+
Seconds: 300 + 300 + 300, // Three times 5 minutes of usage (actually 1 + 1 + 5, but see TODO above).
508523
},
509524
}, "want app usage to match")
510525

511526
// The full timeframe is <= 24h, so the interval matches exactly.
512527
require.Len(t, resp.IntervalReports, 1, "want one interval report")
513528
assert.WithinDuration(t, req.StartTime, resp.IntervalReports[0].StartTime, 0)
514529
assert.WithinDuration(t, req.EndTime, resp.IntervalReports[0].EndTime, 0)
515-
assert.Equal(t, resp.IntervalReports[0].ActiveUsers, int64(1), "want one active user in the interval report")
530+
assert.Equal(t, int64(2), resp.IntervalReports[0].ActiveUsers, "want two active users in the interval report")
516531

517532
// The workspace uses 3 parameters
518533
require.Len(t, resp.Report.ParametersUsage, 3)

0 commit comments

Comments
 (0)