chore: fix TestWorkspaceAutobuild/NextStartAtIsValid flake (#15772)

Fixes https://github.com/coder/internal/issues/238

It appears we haven't got quartz piped through to enough of Coder for
the test to work as I had expected. Using the current time should be
sufficient for this test.
This commit is contained in:
Danielle Maywood
2024-12-06 10:41:31 +00:00
committed by GitHub
parent 069655ace9
commit 67553a7bbe

View File

@ -1117,9 +1117,7 @@ func TestWorkspaceAutobuild(t *testing.T) {
clock = quartz.NewMock(t) clock = quartz.NewMock(t)
) )
// Set the clock to 8AM Monday, 1st January, 2024 to keep clock.Set(dbtime.Now())
// this test deterministic.
clock.Set(time.Date(2024, 1, 1, 8, 0, 0, 0, time.UTC))
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug) logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
client, user := coderdenttest.New(t, &coderdenttest.Options{ client, user := coderdenttest.New(t, &coderdenttest.Options{
@ -1129,7 +1127,7 @@ func TestWorkspaceAutobuild(t *testing.T) {
AutobuildStats: statsCh, AutobuildStats: statsCh,
Logger: &logger, Logger: &logger,
Clock: clock, Clock: clock,
TemplateScheduleStore: schedule.NewEnterpriseTemplateScheduleStore(agplUserQuietHoursScheduleStore(), notifications.NewNoopEnqueuer(), logger, nil), TemplateScheduleStore: schedule.NewEnterpriseTemplateScheduleStore(agplUserQuietHoursScheduleStore(), notifications.NewNoopEnqueuer(), logger, clock),
}, },
LicenseOptions: &coderdenttest.LicenseOptions{ LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{codersdk.FeatureAdvancedTemplateScheduling: 1}, Features: license.Features{codersdk.FeatureAdvancedTemplateScheduling: 1},
@ -1185,7 +1183,7 @@ func TestWorkspaceAutobuild(t *testing.T) {
} }
// Ensure that there is a valid next start at and that is is after // Ensure that there is a valid next start at and that is is after
// the preivous start. // the previous start.
require.NotNil(t, ws.NextStartAt) require.NotNil(t, ws.NextStartAt)
require.Greater(t, *ws.NextStartAt, next) require.Greater(t, *ws.NextStartAt, next)