mirror of
https://github.com/coder/coder.git
synced 2026-06-06 14:38:23 +00:00
fix: align autostart tests with persisted next_start_at (#26037)
`TestExecutorAutostartOK` and its sibling positive autostart tests compute the autobuild tick from `sched.Next(workspace.LatestBuild.CreatedAt)`, but the server persists `next_start_at` from the build's completion time. When build creation and completion straddle the schedule's next fire time, the persisted value advances past the test's tick, the executor's eligibility query (`next_start_at <= tick`) drops the workspace, and the test fails with an empty transitions map. This surfaced in flaky test runs. Add `coderdtest.NextAutostartTick(t, workspace)` which returns `*workspace.NextStartAt`, and use it across the affected positive autostart paths in `coderd/autobuild`, `coderd`, and `enterprise/coderd`. Generated with assistance from Coder Agents.
This commit is contained in:
@@ -1843,6 +1843,18 @@ func UpdateProvisionerLastSeenAt(t *testing.T, db database.Store, id uuid.UUID,
|
||||
t.Logf("Successfully updated provisioner LastSeenAt")
|
||||
}
|
||||
|
||||
// NextAutostartTick returns workspace.NextStartAt for use as the autobuild
|
||||
// tick. The executor's eligibility query checks next_start_at <= tick.
|
||||
// Computing from build.CreatedAt is racy: next_start_at derives from build
|
||||
// completion time, so it can advance past sched.Next(build.CreatedAt) and
|
||||
// the workspace misses the eligibility window.
|
||||
func NextAutostartTick(t testing.TB, workspace codersdk.Workspace) time.Time {
|
||||
t.Helper()
|
||||
require.NotNil(t, workspace.NextStartAt,
|
||||
"workspace next_start_at is nil; ensure autostart is enabled and the latest build has completed before calling NextAutostartTick")
|
||||
return *workspace.NextStartAt
|
||||
}
|
||||
|
||||
func MustWaitForAnyProvisioner(t *testing.T, db database.Store) {
|
||||
t.Helper()
|
||||
ctx := ctxWithProvisionerPermissions(testutil.Context(t, testutil.WaitShort))
|
||||
|
||||
Reference in New Issue
Block a user