MCPcopy Index your code
hub / github.com/coder/coder / requireTerminatedJob

Function requireTerminatedJob

coderd/jobreaper/detector_test.go:88–102  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

86// requireTerminatedJob asserts that a provisioner job was properly terminated
87// by the job reaper with the expected reap type (hung or pending).
88func 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
104func TestDetectorNoJobs(t *testing.T) {
105 t.Parallel()

Calls 3

HelperMethod · 0.65
GetProvisionerJobByIDMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected