requireTerminatedJob asserts that a provisioner job was properly terminated by the job reaper with the expected reap type (hung or pending).
(ctx context.Context, t *testing.T, db database.Store, jobID uuid.UUID, now time.Time, reapType jobreaper.ReapType)
| 86 | // requireTerminatedJob asserts that a provisioner job was properly terminated |
| 87 | // by the job reaper with the expected reap type (hung or pending). |
| 88 | func requireTerminatedJob(ctx context.Context, t *testing.T, db database.Store, jobID uuid.UUID, now time.Time, reapType jobreaper.ReapType) { |
| 89 | t.Helper() |
| 90 | job, err := db.GetProvisionerJobByID(ctx, jobID) |
| 91 | require.NoError(t, err) |
| 92 | require.WithinDuration(t, now, job.UpdatedAt, 30*time.Second) |
| 93 | require.True(t, job.CompletedAt.Valid) |
| 94 | require.WithinDuration(t, now, job.CompletedAt.Time, 30*time.Second) |
| 95 | if reapType == jobreaper.Pending { |
| 96 | require.True(t, job.StartedAt.Valid) |
| 97 | require.WithinDuration(t, now, job.StartedAt.Time, 30*time.Second) |
| 98 | } |
| 99 | require.True(t, job.Error.Valid) |
| 100 | require.Contains(t, job.Error.String, fmt.Sprintf("Build has been detected as %s", reapType)) |
| 101 | require.False(t, job.ErrorCode.Valid) |
| 102 | } |
| 103 | |
| 104 | func TestDetectorNoJobs(t *testing.T) { |
| 105 | t.Parallel() |
no test coverage detected