Skip to content

Commit 3ca17dc

Browse files
craig[bot]dt
andcommitted
Merge #152516
152516: jobs: ensure failure injection targets specific test job r=dt a=dt Add job ID filtering to beforeUpdate hook and allow TestingCreateAndStartJob to respect JobID in record, ensuring failure injection only affects the intended test job rather than any job in the system. Release note: None Fixes #152035. Epic: None Co-authored-by: David Taylor <[email protected]>
2 parents c052356 + 07194ee commit 3ca17dc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pkg/jobs/jobs_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func (rts *registryTestSuite) checkStateChangeLog(
377377
jobEventsLog.PreviousStatus == string(expectedPrevState) &&
378378
jobEventsLog.NewStatus == string(expectedNewState) &&
379379
strings.Contains(jobEventsLog.Error, expectedError) {
380-
rts.statusChangeLogSpy.SetLastNLogsAsUnread(logpb.Channel_OPS, len(logs)-i+1)
380+
rts.statusChangeLogSpy.SetLastNLogsAsUnread(logpb.Channel_OPS, len(logs)-i)
381381
return nil
382382
}
383383
}
@@ -869,10 +869,17 @@ func TestRegistryLifecycle(t *testing.T) {
869869
defer rts.setUp(t)()
870870
defer rts.tearDown()
871871

872+
// Pick an ID so we know which job to mess with.
873+
id := rts.registry.MakeJobID()
874+
rts.mockJob.JobID = id
875+
872876
// Inject an error in the update to move the job to "succeeded" one time.
873877
var failed atomic.Value
874878
failed.Store(false)
875879
rts.beforeUpdate = func(orig, updated jobs.JobMetadata) error {
880+
if orig.ID != id {
881+
return nil
882+
}
876883
if updated.State == jobs.StateSucceeded && !failed.Load().(bool) {
877884
failed.Store(true)
878885
return errors.New("boom")

pkg/jobs/test_helpers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func TestingCreateAndStartJob(
4444
c := config{
4545
jobID: r.MakeJobID(),
4646
}
47+
if record.JobID != 0 {
48+
c.jobID = record.JobID
49+
}
4750
for _, opt := range opts {
4851
opt(&c)
4952
}

0 commit comments

Comments
 (0)