mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix(coderd): ensure agent timings are non-zero on insert (#18065)
Relates to https://github.com/coder/coder/issues/15432 Ensures that no workspace build timings with zero values for started_at or ended_at are inserted into the DB or returned from the API.
This commit is contained in:
@ -215,6 +215,17 @@ func WorkspaceAgent(t testing.TB, db database.Store, orig database.WorkspaceAgen
|
||||
APIKeyScope: takeFirst(orig.APIKeyScope, database.AgentKeyScopeEnumAll),
|
||||
})
|
||||
require.NoError(t, err, "insert workspace agent")
|
||||
if orig.FirstConnectedAt.Valid || orig.LastConnectedAt.Valid || orig.DisconnectedAt.Valid || orig.LastConnectedReplicaID.Valid {
|
||||
err = db.UpdateWorkspaceAgentConnectionByID(genCtx, database.UpdateWorkspaceAgentConnectionByIDParams{
|
||||
ID: agt.ID,
|
||||
FirstConnectedAt: takeFirst(orig.FirstConnectedAt, agt.FirstConnectedAt),
|
||||
LastConnectedAt: takeFirst(orig.LastConnectedAt, agt.LastConnectedAt),
|
||||
DisconnectedAt: takeFirst(orig.DisconnectedAt, agt.DisconnectedAt),
|
||||
LastConnectedReplicaID: takeFirst(orig.LastConnectedReplicaID, agt.LastConnectedReplicaID),
|
||||
UpdatedAt: takeFirst(orig.UpdatedAt, agt.UpdatedAt),
|
||||
})
|
||||
require.NoError(t, err, "update workspace agent first connected at")
|
||||
}
|
||||
return agt
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user