Skip to content

chore: fix flake, use time closer to actual test #11240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: fix flake, use time closer to actual test
The tests were queued, and the autostart time was being set
to the time the table was created, not when the test was actually
being run. This diff was causing failures in CI
  • Loading branch information
Emyrk committed Dec 18, 2023
commit 35bc999edf4b5669953ac9dd23ae4c962d3bb0de
15 changes: 10 additions & 5 deletions coderd/agentapi/activitybump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
templateTTL time.Duration
templateDisallowsUserAutostop bool
expectedBump time.Duration
nextAutostart time.Time
// If the tests get queued, we need to be able to set the next autostart
// based on the actual time the unit test is running.
nextAutostart func(now time.Time) time.Time
}{
{
name: "NotFinishedYet",
Expand Down Expand Up @@ -93,7 +95,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
buildDeadlineOffset: ptr.Ref(-30 * time.Minute),
workspaceTTL: 8 * time.Hour,
expectedBump: 8*time.Hour + 30*time.Minute,
nextAutostart: time.Now().Add(time.Minute * 30),
nextAutostart: func(now time.Time) time.Time { return now.Add(time.Minute * 30) },
},
{
name: "MaxDeadline",
Expand Down Expand Up @@ -127,20 +129,23 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
// by the template TTL instead.
name: "TemplateDisallowsUserAutostop",
transition: database.WorkspaceTransitionStart,
jobCompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now().Add(-7 * time.Hour)},
jobCompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now().Add(-3 * time.Hour)},
buildDeadlineOffset: ptr.Ref(-30 * time.Minute),
workspaceTTL: 2 * time.Hour,
templateTTL: 10 * time.Hour,
templateDisallowsUserAutostop: true,
expectedBump: 10*time.Hour + (time.Minute * 30),
nextAutostart: time.Now().Add(time.Minute * 30),
nextAutostart: func(now time.Time) time.Time { return now.Add(time.Minute * 30) },
},
} {
tt := tt
for _, tz := range timezones {
tz := tz
t.Run(tt.name+"/"+tz, func(t *testing.T) {
t.Parallel()
if tt.nextAutostart == nil {
tt.nextAutostart = func(now time.Time) time.Time { return time.Time{} }
}

var (
now = dbtime.Now()
Expand Down Expand Up @@ -237,7 +242,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {

// Bump duration is measured from the time of the bump, so we measure from here.
start := dbtime.Now()
agentapi.ActivityBumpWorkspace(ctx, log, db, bld.WorkspaceID, tt.nextAutostart)
activityBumpWorkspace(ctx, log, db, bld.WorkspaceID, tt.nextAutostart(start))
end := dbtime.Now()

// Validate our state after bump
Expand Down