Skip to content

Commit

Permalink
upgrades: deflake TestBackfillJobsInfoTable
Browse files Browse the repository at this point in the history
Previously, this test created jobs that could be adopted
during test execution causing the number of payload/progress
updates to be variable. With this change we create startable
jobs so that they are not adopted and the number of payload/progress
remain constant.

Fixes: cockroachdb#103046
Release note: None
  • Loading branch information
adityamaru committed Jun 14, 2023
1 parent c1a71cf commit f523899
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pkg/upgrade/upgrades/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ go_test(
shard_count = 16,
deps = [
"//pkg/base",
"//pkg/ccl/backupccl",
"//pkg/ccl/changefeedccl",
"//pkg/cloud/userfile",
"//pkg/clusterversion",
"//pkg/jobs",
Expand Down
21 changes: 10 additions & 11 deletions pkg/upgrade/upgrades/backfill_job_info_table_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
_ "github.com/cockroachdb/cockroach/pkg/ccl/backupccl"
_ "github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/jobs"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/server"
"github.com/cockroachdb/cockroach/pkg/sql"
"github.com/cockroachdb/cockroach/pkg/sql/isql"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
"github.com/cockroachdb/cockroach/pkg/upgrade/upgrades"
Expand Down Expand Up @@ -53,25 +57,20 @@ func TestBackfillJobsInfoTable(t *testing.T) {
r := tc.Server(0).JobRegistry().(*jobs.Registry)
sqlDB := sqlutils.MakeSQLRunner(tc.ServerConn(0))
defer tc.Stopper().Stop(ctx)
jobspb.ForEachType(func(typ jobspb.Type) {
// The upgrade creates migration and schemachange jobs, so we do not
// need to create more. We should not override resumers for these job types,
// otherwise the upgrade will hang.
if typ != jobspb.TypeMigration && typ != jobspb.TypeSchemaChange {
r.TestingWrapResumerConstructor(typ, func(r jobs.Resumer) jobs.Resumer { return &fakeResumer{} })
}
}, false)

createJob := func(id jobspb.JobID, details jobspb.Details, progress jobspb.ProgressDetails) *jobs.Job {
createJob := func(id jobspb.JobID, details jobspb.Details, progress jobspb.ProgressDetails) {
defaultRecord := jobs.Record{
Details: details,
Progress: progress,
Username: username.TestUserName(),
}

job, err := r.CreateJobWithTxn(ctx, defaultRecord, id, nil /* txn */)
var job *jobs.StartableJob
db := tc.Server(0).InternalDB().(*sql.InternalDB)
err := db.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
return r.CreateStartableJobWithTxn(ctx, &job, id, txn, defaultRecord)
})
require.NoError(t, err)
return job
}

// Create a few different types of jobs.
Expand Down

0 comments on commit f523899

Please sign in to comment.