diff --git a/cli/schedule_test.go b/cli/schedule_test.go index bc473279f7..ed9c5b1743 100644 --- a/cli/schedule_test.go +++ b/cli/schedule_test.go @@ -352,8 +352,6 @@ func TestScheduleOverride(t *testing.T) { require.NoError(t, err, "invalid schedule") ownerClient, _, _, ws := setupTestSchedule(t, sched) now := time.Now() - // To avoid the likelihood of time-related flakes, only matching up to the hour. - expectedDeadline := now.In(loc).Add(10 * time.Hour).Format("2006-01-02T15:") // When: we override the stop schedule inv, root := clitest.New(t, @@ -364,6 +362,19 @@ func TestScheduleOverride(t *testing.T) { pty := ptytest.New(t).Attach(inv) require.NoError(t, inv.Run()) + // Fetch the workspace to get the actual deadline set by the + // server. Computing our own expected deadline from a separately + // captured time.Now() is racy: the CLI command calls time.Now() + // internally, and with the Asia/Kolkata +05:30 offset the hour + // boundary falls at :30 UTC minutes. A small delay between our + // time.Now() and the command's is enough to land in different + // hours. + updated, err := ownerClient.Workspace(context.Background(), ws[0].ID) + require.NoError(t, err) + require.False(t, updated.LatestBuild.Deadline.IsZero(), "deadline should be set after extend") + require.WithinDuration(t, now.Add(10*time.Hour), updated.LatestBuild.Deadline.Time, 5*time.Minute) + expectedDeadline := updated.LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339) + // Then: the updated schedule should be shown pty.ExpectMatch(ws[0].OwnerName + "/" + ws[0].Name) pty.ExpectMatch(sched.Humanize())