@@ -274,6 +274,7 @@ func TestTemplateInsights(t *testing.T) {
274
274
client , _ , coderdAPI := coderdtest .NewWithAPI (t , opts )
275
275
276
276
user := coderdtest .CreateFirstUser (t , client )
277
+ _ , otherUser := coderdtest .CreateAnotherUser (t , client , user .OrganizationID )
277
278
authToken := uuid .NewString ()
278
279
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , & echo.Responses {
279
280
Parse : echo .ParseComplete ,
@@ -390,6 +391,20 @@ func TestTemplateInsights(t *testing.T) {
390
391
SessionEndedAt : requestStartTime .Add (1 * time .Minute ),
391
392
Requests : 1 ,
392
393
},
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
+ },
393
408
{
394
409
UserID : user .UserID ,
395
410
WorkspaceID : workspace .ID ,
@@ -482,7 +497,7 @@ func TestTemplateInsights(t *testing.T) {
482
497
483
498
assert .WithinDuration (t , req .StartTime , resp .Report .StartTime , 0 )
484
499
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 " )
486
501
var gotApps []codersdk.TemplateAppUsage
487
502
// Check builtin apps usage.
488
503
for _ , app := range resp .Report .AppsUsage {
@@ -504,15 +519,15 @@ func TestTemplateInsights(t *testing.T) {
504
519
Slug : testAppSlug ,
505
520
DisplayName : testAppName ,
506
521
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).
508
523
},
509
524
}, "want app usage to match" )
510
525
511
526
// The full timeframe is <= 24h, so the interval matches exactly.
512
527
require .Len (t , resp .IntervalReports , 1 , "want one interval report" )
513
528
assert .WithinDuration (t , req .StartTime , resp .IntervalReports [0 ].StartTime , 0 )
514
529
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" )
516
531
517
532
// The workspace uses 3 parameters
518
533
require .Len (t , resp .Report .ParametersUsage , 3 )
0 commit comments