Skip to content

Commit 1b35ac8

Browse files
authored
fix: ensure agent DisconnectedAt is greater than or equal LastConnectedAt (#6692)
See https://github.com/coder/coder/actions/runs/4471502401/jobs/7856475920
1 parent fce8a4a commit 1b35ac8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

coderd/workspaceagents.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,9 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
915915
// to start up.
916916
workspaceAgent.Status = codersdk.WorkspaceAgentConnecting
917917
}
918-
case dbAgent.DisconnectedAt.Time.After(dbAgent.LastConnectedAt.Time):
918+
// We check before instead of after because last connected at and
919+
// disconnected at can be equal timestamps in tight-timed tests.
920+
case !dbAgent.DisconnectedAt.Time.Before(dbAgent.LastConnectedAt.Time):
919921
// If we've disconnected after our last connection, we know the
920922
// agent is no longer connected.
921923
workspaceAgent.Status = codersdk.WorkspaceAgentDisconnected

coderd/workspaces_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,12 @@ func TestWorkspaceUpdateTTL(t *testing.T) {
14021402

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

1405-
require.Len(t, auditor.AuditLogs, 7)
1406-
assert.Equal(t, database.AuditActionWrite, auditor.AuditLogs[6].Action)
1405+
require.Eventually(t, func() bool {
1406+
if len(auditor.AuditLogs) != 7 {
1407+
return false
1408+
}
1409+
return auditor.AuditLogs[6].Action == database.AuditActionWrite
1410+
}, testutil.WaitMedium, testutil.IntervalFast, "expected audit log to be written")
14071411
})
14081412
}
14091413

0 commit comments

Comments
 (0)