Skip to content

feat: add activity status and autostop reason to workspace overview #11987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Feb 13, 2024
Prev Previous commit
Next Next commit
dbM
  • Loading branch information
aslilac committed Feb 12, 2024
commit 8a52a23dddace90d98c47895ec2012bef5f750f4
20 changes: 10 additions & 10 deletions coderd/agentapi/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestUpdateStates(t *testing.T) {

var (
now = dbtime.Now()
db = dbmock.NewMockStore(gomock.NewController(t))
dbM = dbmock.NewMockStore(gomock.NewController(t))
ps = pubsub.NewInMemory()

templateScheduleStore = schedule.MockTemplateScheduleStore{
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestUpdateStates(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
Database: db,
Database: dbM,
Pubsub: ps,
StatsBatcher: batcher,
TemplateScheduleStore: templateScheduleStorePtr(templateScheduleStore),
Expand All @@ -148,25 +148,25 @@ func TestUpdateStates(t *testing.T) {
}

// Workspace gets fetched.
db.EXPECT().GetWorkspaceByAgentID(gomock.Any(), agent.ID).Return(database.GetWorkspaceByAgentIDRow{
dbM.EXPECT().GetWorkspaceByAgentID(gomock.Any(), agent.ID).Return(database.GetWorkspaceByAgentIDRow{
Workspace: workspace,
TemplateName: template.Name,
}, nil)

// We expect an activity bump because ConnectionCount > 0.
db.EXPECT().ActivityBumpWorkspace(gomock.Any(), database.ActivityBumpWorkspaceParams{
dbM.EXPECT().ActivityBumpWorkspace(gomock.Any(), database.ActivityBumpWorkspaceParams{
WorkspaceID: workspace.ID,
NextAutostart: time.Time{}.UTC(),
}).Return(nil)

// Workspace last used at gets bumped.
db.EXPECT().UpdateWorkspaceLastUsedAt(gomock.Any(), database.UpdateWorkspaceLastUsedAtParams{
dbM.EXPECT().UpdateWorkspaceLastUsedAt(gomock.Any(), database.UpdateWorkspaceLastUsedAtParams{
ID: workspace.ID,
LastUsedAt: now,
}).Return(nil)

// User gets fetched to hit the UpdateAgentMetricsFn.
db.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)

resp, err := api.UpdateStats(context.Background(), req)
require.NoError(t, err)
Expand All @@ -192,7 +192,7 @@ func TestUpdateStates(t *testing.T) {

var (
now = dbtime.Now()
db = dbmock.NewMockStore(gomock.NewController(t))
dbM = dbmock.NewMockStore(gomock.NewController(t))
ps = pubsub.NewInMemory()
templateScheduleStore = schedule.MockTemplateScheduleStore{
GetFn: func(context.Context, database.Store, uuid.UUID) (schedule.TemplateScheduleOptions, error) {
Expand All @@ -218,7 +218,7 @@ func TestUpdateStates(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
Database: db,
Database: dbM,
Pubsub: ps,
StatsBatcher: batcher,
TemplateScheduleStore: templateScheduleStorePtr(templateScheduleStore),
Expand All @@ -231,13 +231,13 @@ func TestUpdateStates(t *testing.T) {
}

// Workspace gets fetched.
db.EXPECT().GetWorkspaceByAgentID(gomock.Any(), agent.ID).Return(database.GetWorkspaceByAgentIDRow{
dbM.EXPECT().GetWorkspaceByAgentID(gomock.Any(), agent.ID).Return(database.GetWorkspaceByAgentIDRow{
Workspace: workspace,
TemplateName: template.Name,
}, nil)

// Workspace last used at gets bumped.
db.EXPECT().UpdateWorkspaceLastUsedAt(gomock.Any(), database.UpdateWorkspaceLastUsedAtParams{
dbM.EXPECT().UpdateWorkspaceLastUsedAt(gomock.Any(), database.UpdateWorkspaceLastUsedAtParams{
ID: workspace.ID,
LastUsedAt: now,
}).Return(nil)
Expand Down