Skip to content

Commit

Permalink
jobs: fix batch jobs creation test
Browse files Browse the repository at this point in the history
Commit cockroachdb#67991 introduced a test that turned out to be flaky.
The test runs out of memory sometimes as it creates a very
large batch of jobs. This fix disables job adoptions to
avoid large memory use.

Release note: None

Fixes: cockroachdb#68962
  • Loading branch information
Sajjad Rizvi committed Aug 17, 2021
1 parent 4aa67c3 commit 913a1f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions pkg/jobs/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,9 @@ func (r *Registry) stepThroughStateMachine(
}

func (r *Registry) adoptionDisabled(ctx context.Context) bool {
if r.knobs.DisableAdoptions {
return true
}
if r.preventAdoptionFile != "" {
if _, err := os.Stat(r.preventAdoptionFile); err != nil {
if !oserror.IsNotExist(err) {
Expand Down
12 changes: 5 additions & 7 deletions pkg/jobs/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ func TestBatchJobsCreation(t *testing.T) {

args := base.TestServerArgs{
Knobs: base.TestingKnobs{
JobsTestingKnobs: NewTestingKnobsWithShortIntervals(),
// Avoiding jobs to be adopted.
JobsTestingKnobs: &TestingKnobs{
DisableAdoptions: true,
},
},
}

Expand Down Expand Up @@ -345,13 +348,8 @@ func TestBatchJobsCreation(t *testing.T) {
return err
}))
require.Equal(t, len(jobIDs), test.batchSize)
// Wait for the jobs to complete.
tdb.CheckQueryResultsRetry(t, "SELECT count(*) FROM [SHOW JOBS]",
tdb.CheckQueryResults(t, "SELECT count(*) FROM [SHOW JOBS]",
[][]string{{fmt.Sprintf("%d", test.batchSize)}})
for _, id := range jobIDs {
tdb.CheckQueryResultsRetry(t, fmt.Sprintf("SELECT status FROM system.jobs WHERE id = '%d'", id),
[][]string{{"succeeded"}})
}
}
})
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/jobs/testing_knobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type TestingKnobs struct {

// TimeSource replaces registry's clock.
TimeSource *hlc.Clock

// DisableAdoptions disables job adoptions.
DisableAdoptions bool
}

// ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.
Expand Down

0 comments on commit 913a1f4

Please sign in to comment.