@@ -325,6 +325,7 @@ func TestUpdateStates(t *testing.T) {
325
325
"dean" : 2 ,
326
326
},
327
327
ConnectionCount : 3 ,
328
+ SessionCountSsh : 3 ,
328
329
},
329
330
}
330
331
)
@@ -409,11 +410,7 @@ func TestUpdateStates(t *testing.T) {
409
410
}
410
411
batcher = & workspacestatstest.StatsBatcher {}
411
412
updateAgentMetricsFnCalled = false
412
- tickCh = make (chan time.Time )
413
- flushCh = make (chan int , 1 )
414
- wut = workspacestats .NewTracker (dbM ,
415
- workspacestats .TrackerWithTickFlush (tickCh , flushCh ),
416
- )
413
+ wut = workspacestats .NewTracker (dbM )
417
414
418
415
req = & agentproto.UpdateStatsRequest {
419
416
Stats : & agentproto.Stats {
@@ -479,53 +476,22 @@ func TestUpdateStates(t *testing.T) {
479
476
// Workspace gets fetched.
480
477
dbM .EXPECT ().GetWorkspaceByAgentID (gomock .Any (), agent .ID ).Return (workspace , nil )
481
478
482
- // We expect an activity bump because ConnectionCount > 0.
483
- dbM .EXPECT ().ActivityBumpWorkspace (gomock .Any (), database.ActivityBumpWorkspaceParams {
484
- WorkspaceID : workspace .ID ,
485
- NextAutostart : time.Time {}.UTC (),
486
- }).Return (nil )
487
-
488
- // Workspace last used at gets bumped.
489
- dbM .EXPECT ().BatchUpdateWorkspaceLastUsedAt (gomock .Any (), database.BatchUpdateWorkspaceLastUsedAtParams {
490
- IDs : []uuid.UUID {workspace .ID },
491
- LastUsedAt : now ,
492
- }).Return (nil )
493
-
494
479
// User gets fetched to hit the UpdateAgentMetricsFn.
495
480
dbM .EXPECT ().GetUserByID (gomock .Any (), user .ID ).Return (user , nil )
496
481
497
- // Ensure that pubsub notifications are sent.
498
- notifyDescription := make (chan []byte )
499
- ps .Subscribe (codersdk .WorkspaceNotifyChannel (workspace .ID ), func (_ context.Context , description []byte ) {
500
- go func () {
501
- notifyDescription <- description
502
- }()
503
- })
504
-
505
482
resp , err := api .UpdateStats (context .Background (), req )
506
483
require .NoError (t , err )
507
484
require .Equal (t , & agentproto.UpdateStatsResponse {
508
485
ReportInterval : durationpb .New (10 * time .Second ),
509
486
}, resp )
510
487
511
- tickCh <- now
512
- count := <- flushCh
513
- require .Equal (t , 1 , count , "expected one flush with one id" )
514
-
515
488
batcher .Mu .Lock ()
516
489
defer batcher .Mu .Unlock ()
517
490
require .EqualValues (t , 1 , batcher .Called )
518
491
require .EqualValues (t , 0 , batcher .LastStats .SessionCountSsh )
519
492
require .EqualValues (t , 0 , batcher .LastStats .SessionCountJetbrains )
520
493
require .EqualValues (t , 0 , batcher .LastStats .SessionCountVscode )
521
494
require .EqualValues (t , 0 , batcher .LastStats .SessionCountReconnectingPty )
522
- ctx := testutil .Context (t , testutil .WaitShort )
523
- select {
524
- case <- ctx .Done ():
525
- t .Error ("timed out while waiting for pubsub notification" )
526
- case description := <- notifyDescription :
527
- require .Equal (t , description , []byte {})
528
- }
529
495
require .True (t , updateAgentMetricsFnCalled )
530
496
})
531
497
}
0 commit comments