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:
Cian Johnston
2025-05-29 13:36:06 +01:00
committed by GitHub
parent 5f34d01906
commit 776c144128
8 changed files with 217 additions and 25 deletions

View File

@ -2,6 +2,7 @@ package coderd_test
import (
"context"
"database/sql"
"errors"
"fmt"
"net/http"
@ -1736,7 +1737,8 @@ func TestWorkspaceBuildTimings(t *testing.T) {
JobID: build.JobID,
})
agent := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{
ResourceID: resource.ID,
ResourceID: resource.ID,
FirstConnectedAt: sql.NullTime{Valid: true, Time: dbtime.Now().Add(-time.Hour)},
})
// When: fetching timings for the build
@ -1767,7 +1769,8 @@ func TestWorkspaceBuildTimings(t *testing.T) {
agents := make([]database.WorkspaceAgent, 5)
for i := range agents {
agents[i] = dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{
ResourceID: resource.ID,
ResourceID: resource.ID,
FirstConnectedAt: sql.NullTime{Valid: true, Time: dbtime.Now().Add(-time.Duration(i) * time.Hour)},
})
}