Skip to content

Commit 1b9be00

Browse files
committed
Revert "fix tests"
This reverts commit 61f2b7e.
1 parent 61f2b7e commit 1b9be00

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

coderd/agentapi/stats_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ func TestUpdateStates(t *testing.T) {
230230
TemplateName: template.Name,
231231
}, nil)
232232

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+
233239
_, err := api.UpdateStats(context.Background(), req)
234240
require.NoError(t, err)
235241
})
@@ -313,7 +319,6 @@ func TestUpdateStates(t *testing.T) {
313319
"dean": 2,
314320
},
315321
ConnectionCount: 3,
316-
SessionCountSsh: 3,
317322
},
318323
}
319324
)
@@ -350,7 +355,7 @@ func TestUpdateStates(t *testing.T) {
350355
TemplateName: template.Name,
351356
}, nil)
352357

353-
// We expect an activity bump because SessionCountSsh > 0. However, the
358+
// We expect an activity bump because ConnectionCount > 0. However, the
354359
// next autostart time will be set on the bump.
355360
dbM.EXPECT().ActivityBumpWorkspace(gomock.Any(), database.ActivityBumpWorkspaceParams{
356361
WorkspaceID: workspace.ID,
@@ -461,9 +466,29 @@ func TestUpdateStates(t *testing.T) {
461466
TemplateName: template.Name,
462467
}, nil)
463468

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+
464481
// User gets fetched to hit the UpdateAgentMetricsFn.
465482
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)
466483

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+
467492
resp, err := api.UpdateStats(context.Background(), req)
468493
require.NoError(t, err)
469494
require.Equal(t, &agentproto.UpdateStatsResponse{
@@ -477,6 +502,13 @@ func TestUpdateStates(t *testing.T) {
477502
require.EqualValues(t, 0, batcher.LastStats.SessionCountJetbrains)
478503
require.EqualValues(t, 0, batcher.LastStats.SessionCountVscode)
479504
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+
}
480512
require.True(t, updateAgentMetricsFnCalled)
481513
})
482514
}

0 commit comments

Comments
 (0)