Skip to content

fix: ensure agent DisconnectedAt is greater than or equal LastConnectedAt #6692

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 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
// to start up.
workspaceAgent.Status = codersdk.WorkspaceAgentConnecting
}
case dbAgent.DisconnectedAt.Time.After(dbAgent.LastConnectedAt.Time):
// We check before instead of after because last connected at and
// disconnected at can be equal timestamps in tight-timed tests.
case !dbAgent.DisconnectedAt.Time.Before(dbAgent.LastConnectedAt.Time):
// If we've disconnected after our last connection, we know the
// agent is no longer connected.
workspaceAgent.Status = codersdk.WorkspaceAgentDisconnected
Expand Down
8 changes: 6 additions & 2 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,12 @@ func TestWorkspaceUpdateTTL(t *testing.T) {

require.Equal(t, testCase.ttlMillis, updated.TTLMillis, "expected autostop ttl to equal requested")

require.Len(t, auditor.AuditLogs, 7)
assert.Equal(t, database.AuditActionWrite, auditor.AuditLogs[6].Action)
require.Eventually(t, func() bool {
if len(auditor.AuditLogs) != 7 {
return false
}
return auditor.AuditLogs[6].Action == database.AuditActionWrite
}, testutil.WaitMedium, testutil.IntervalFast, "expected audit log to be written")
})
}

Expand Down