@@ -230,6 +230,12 @@ func TestUpdateStates(t *testing.T) {
230
230
TemplateName : template .Name ,
231
231
}, nil )
232
232
233
+ // Workspace last used at gets bumped.
234
+ dbM .EXPECT ().UpdateWorkspaceLastUsedAt (gomock .Any (), database.UpdateWorkspaceLastUsedAtParams {
235
+ ID : workspace .ID ,
236
+ LastUsedAt : now ,
237
+ }).Return (nil )
238
+
233
239
_ , err := api .UpdateStats (context .Background (), req )
234
240
require .NoError (t , err )
235
241
})
@@ -313,7 +319,6 @@ func TestUpdateStates(t *testing.T) {
313
319
"dean" : 2 ,
314
320
},
315
321
ConnectionCount : 3 ,
316
- SessionCountSsh : 3 ,
317
322
},
318
323
}
319
324
)
@@ -350,7 +355,7 @@ func TestUpdateStates(t *testing.T) {
350
355
TemplateName : template .Name ,
351
356
}, nil )
352
357
353
- // We expect an activity bump because SessionCountSsh > 0. However, the
358
+ // We expect an activity bump because ConnectionCount > 0. However, the
354
359
// next autostart time will be set on the bump.
355
360
dbM .EXPECT ().ActivityBumpWorkspace (gomock .Any (), database.ActivityBumpWorkspaceParams {
356
361
WorkspaceID : workspace .ID ,
@@ -461,9 +466,29 @@ func TestUpdateStates(t *testing.T) {
461
466
TemplateName : template .Name ,
462
467
}, nil )
463
468
469
+ // We expect an activity bump because ConnectionCount > 0.
470
+ dbM .EXPECT ().ActivityBumpWorkspace (gomock .Any (), database.ActivityBumpWorkspaceParams {
471
+ WorkspaceID : workspace .ID ,
472
+ NextAutostart : time.Time {}.UTC (),
473
+ }).Return (nil )
474
+
475
+ // Workspace last used at gets bumped.
476
+ dbM .EXPECT ().UpdateWorkspaceLastUsedAt (gomock .Any (), database.UpdateWorkspaceLastUsedAtParams {
477
+ ID : workspace .ID ,
478
+ LastUsedAt : now ,
479
+ }).Return (nil )
480
+
464
481
// User gets fetched to hit the UpdateAgentMetricsFn.
465
482
dbM .EXPECT ().GetUserByID (gomock .Any (), user .ID ).Return (user , nil )
466
483
484
+ // Ensure that pubsub notifications are sent.
485
+ notifyDescription := make (chan []byte )
486
+ ps .Subscribe (codersdk .WorkspaceNotifyChannel (workspace .ID ), func (_ context.Context , description []byte ) {
487
+ go func () {
488
+ notifyDescription <- description
489
+ }()
490
+ })
491
+
467
492
resp , err := api .UpdateStats (context .Background (), req )
468
493
require .NoError (t , err )
469
494
require .Equal (t , & agentproto.UpdateStatsResponse {
@@ -477,6 +502,13 @@ func TestUpdateStates(t *testing.T) {
477
502
require .EqualValues (t , 0 , batcher .LastStats .SessionCountJetbrains )
478
503
require .EqualValues (t , 0 , batcher .LastStats .SessionCountVscode )
479
504
require .EqualValues (t , 0 , batcher .LastStats .SessionCountReconnectingPty )
505
+ ctx := testutil .Context (t , testutil .WaitShort )
506
+ select {
507
+ case <- ctx .Done ():
508
+ t .Error ("timed out while waiting for pubsub notification" )
509
+ case description := <- notifyDescription :
510
+ require .Equal (t , description , []byte {})
511
+ }
480
512
require .True (t , updateAgentMetricsFnCalled )
481
513
})
482
514
}
0 commit comments