(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func Test_ActivityBumpWorkspace(t *testing.T) { |
| 22 | t.Parallel() |
| 23 | |
| 24 | // We test the below in multiple timezones specifically |
| 25 | // chosen to trigger timezone-related bugs. |
| 26 | timezones := []string{ |
| 27 | "Asia/Kolkata", // No DST, positive fractional offset |
| 28 | "America/St_Johns", // DST, negative fractional offset |
| 29 | "Europe/Paris", // DST, positive offset |
| 30 | "US/Arizona", // No DST, negative offset |
| 31 | "UTC", // Baseline |
| 32 | } |
| 33 | |
| 34 | for _, tt := range []struct { |
| 35 | name string |
| 36 | transition database.WorkspaceTransition |
| 37 | jobCompletedAt sql.NullTime |
| 38 | buildDeadlineOffset *time.Duration |
| 39 | maxDeadlineOffset *time.Duration |
| 40 | workspaceTTL time.Duration |
| 41 | templateTTL time.Duration |
| 42 | templateActivityBump time.Duration |
| 43 | templateDisallowsUserAutostop bool |
| 44 | expectedBump time.Duration |
| 45 | // If the tests get queued, we need to be able to set the next autostart |
| 46 | // based on the actual time the unit test is running. |
| 47 | nextAutostart func(now time.Time) time.Time |
| 48 | }{ |
| 49 | { |
| 50 | name: "NotFinishedYet", |
| 51 | transition: database.WorkspaceTransitionStart, |
| 52 | jobCompletedAt: sql.NullTime{}, |
| 53 | buildDeadlineOffset: ptr.Ref(8 * time.Hour), |
| 54 | workspaceTTL: 8 * time.Hour, |
| 55 | expectedBump: 0, |
| 56 | }, |
| 57 | { |
| 58 | name: "ManualShutdown", |
| 59 | transition: database.WorkspaceTransitionStart, |
| 60 | jobCompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now()}, |
| 61 | buildDeadlineOffset: nil, |
| 62 | expectedBump: 0, |
| 63 | }, |
| 64 | { |
| 65 | name: "NotTimeToBumpYet", |
| 66 | transition: database.WorkspaceTransitionStart, |
| 67 | jobCompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now()}, |
| 68 | buildDeadlineOffset: ptr.Ref(8 * time.Hour), |
| 69 | workspaceTTL: 8 * time.Hour, |
| 70 | expectedBump: 0, |
| 71 | }, |
| 72 | { |
| 73 | // Expected bump is 0 because the original deadline is more than 1 hour |
| 74 | // out, so a bump would decrease the deadline. |
| 75 | name: "BumpLessThanDeadline", |
| 76 | transition: database.WorkspaceTransitionStart, |
| 77 | jobCompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now().Add(-30 * time.Minute)}, |
| 78 | buildDeadlineOffset: ptr.Ref(8*time.Hour - 30*time.Minute), |
nothing calls this directly
no test coverage detected