Skip to content

Commit d702dca

Browse files
committed
fix: do not bump activity with no sessions
1 parent 9e07bb4 commit d702dca

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

coderd/agentapi/stats_test.go

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ func TestUpdateStates(t *testing.T) {
325325
"dean": 2,
326326
},
327327
ConnectionCount: 3,
328+
SessionCountSsh: 3,
328329
},
329330
}
330331
)
@@ -409,11 +410,7 @@ func TestUpdateStates(t *testing.T) {
409410
}
410411
batcher = &workspacestatstest.StatsBatcher{}
411412
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)
417414

418415
req = &agentproto.UpdateStatsRequest{
419416
Stats: &agentproto.Stats{
@@ -479,53 +476,22 @@ func TestUpdateStates(t *testing.T) {
479476
// Workspace gets fetched.
480477
dbM.EXPECT().GetWorkspaceByAgentID(gomock.Any(), agent.ID).Return(workspace, nil)
481478

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

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-
505482
resp, err := api.UpdateStats(context.Background(), req)
506483
require.NoError(t, err)
507484
require.Equal(t, &agentproto.UpdateStatsResponse{
508485
ReportInterval: durationpb.New(10 * time.Second),
509486
}, resp)
510487

511-
tickCh <- now
512-
count := <-flushCh
513-
require.Equal(t, 1, count, "expected one flush with one id")
514-
515488
batcher.Mu.Lock()
516489
defer batcher.Mu.Unlock()
517490
require.EqualValues(t, 1, batcher.Called)
518491
require.EqualValues(t, 0, batcher.LastStats.SessionCountSsh)
519492
require.EqualValues(t, 0, batcher.LastStats.SessionCountJetbrains)
520493
require.EqualValues(t, 0, batcher.LastStats.SessionCountVscode)
521494
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-
}
529495
require.True(t, updateAgentMetricsFnCalled)
530496
})
531497
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy