Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-21.1: jobs: fix flakey TestMetrics #66661

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions pkg/jobs/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2534,18 +2534,20 @@ func TestMetrics(t *testing.T) {
jobs.RegisterConstructor(jobspb.TypeImport, func(_ *jobs.Job, _ *cluster.Settings) jobs.Resumer {
return res
})
setup := func(t *testing.T) (s serverutils.TestServerInterface, r *jobs.Registry, cleanup func()) {
setup := func(t *testing.T) (
s serverutils.TestServerInterface, db *gosql.DB, r *jobs.Registry, cleanup func(),
) {
jobConstructorCleanup := jobs.ResetConstructors()
s, _, _ = serverutils.StartServer(t, base.TestServerArgs{})
s, db, _ = serverutils.StartServer(t, base.TestServerArgs{})
r = s.JobRegistry().(*jobs.Registry)
return s, r, func() {
return s, db, r, func() {
jobConstructorCleanup()
s.Stopper().Stop(ctx)
}
}

t.Run("success", func(t *testing.T) {
_, registry, cleanup := setup(t)
_, _, registry, cleanup := setup(t)
defer cleanup()
rec := jobs.Record{
DescriptorIDs: []descpb.ID{1},
Expand All @@ -2561,7 +2563,7 @@ func TestMetrics(t *testing.T) {
int64EqSoon(t, backupMetrics.ResumeCompleted.Count, 1)
})
t.Run("restart, pause, resume, then success", func(t *testing.T) {
_, registry, cleanup := setup(t)
_, db, registry, cleanup := setup(t)
defer cleanup()
rec := jobs.Record{
DescriptorIDs: []descpb.ID{1},
Expand Down Expand Up @@ -2592,6 +2594,12 @@ func TestMetrics(t *testing.T) {
require.Equal(t, int64(0), importMetrics.ResumeCompleted.Count())
require.Equal(t, int64(0), importMetrics.CurrentlyRunning.Value())
}
{
// Wait for the job to be marked paused.
tdb := sqlutils.MakeSQLRunner(db)
q := fmt.Sprintf("SELECT status FROM system.jobs WHERE id = %d", jobID)
tdb.CheckQueryResultsRetry(t, q, [][]string{{"paused"}})
}
{
// Now resume the job and let it succeed.
require.NoError(t, registry.Unpause(ctx, nil, jobID))
Expand All @@ -2602,7 +2610,7 @@ func TestMetrics(t *testing.T) {
}
})
t.Run("failure then restarts in revert", func(t *testing.T) {
_, registry, cleanup := setup(t)
_, _, registry, cleanup := setup(t)
defer cleanup()
rec := jobs.Record{
DescriptorIDs: []descpb.ID{1},
Expand Down Expand Up @@ -2637,7 +2645,7 @@ func TestMetrics(t *testing.T) {
}
})
t.Run("fail, pause, resume, then success on failure", func(t *testing.T) {
_, registry, cleanup := setup(t)
_, db, registry, cleanup := setup(t)
defer cleanup()
rec := jobs.Record{
DescriptorIDs: []descpb.ID{1},
Expand Down Expand Up @@ -2668,6 +2676,12 @@ func TestMetrics(t *testing.T) {
require.Equal(t, int64(0), importMetrics.ResumeCompleted.Count())
require.Equal(t, int64(0), importMetrics.CurrentlyRunning.Value())
}
{
// Wait for the job to be marked paused.
tdb := sqlutils.MakeSQLRunner(db)
q := fmt.Sprintf("SELECT status FROM system.jobs WHERE id = %d", jobID)
tdb.CheckQueryResultsRetry(t, q, [][]string{{"paused"}})
}
{
// Now resume the job and let it succeed.
require.NoError(t, registry.Unpause(ctx, nil, jobID))
Expand Down