Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
124597: importer: harden TestImportWorkerFailure r=yuzefovich a=yuzefovich

This commit hardens `TestImportWorkerFailure` in the following ways:
- previously, we picked the latest job when blocking until it succeeds, but it could be not the import job we're interested in. Now we add a filter to the query for the job type and status.
- we now add some retries around SELECT * queries at the end of the test that ensure the state of the table. It seems like there might be a race between the import finishing and brining the table online, so the retries seem reasonable.

Fixes: cockroachdb#120607.

Release note: None

Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
craig[bot] and yuzefovich committed May 23, 2024
2 parents 565fa54 + b392062 commit 748e9f1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/sql/importer/import_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5365,7 +5365,8 @@ func TestImportWorkerFailure(t *testing.T) {
t.Fatalf("%s: query returned before expected: %s", err, query)
}
var jobID jobspb.JobID
sqlDB.QueryRow(t, `SELECT id FROM system.jobs ORDER BY created DESC LIMIT 1`).Scan(&jobID)
sqlDB.QueryRow(t, `SELECT id FROM system.jobs WHERE status = 'running'
AND job_type = 'IMPORT' ORDER BY created DESC LIMIT 1`).Scan(&jobID)

// Shut down a node.
tc.StopServer(1)
Expand All @@ -5378,13 +5379,13 @@ func TestImportWorkerFailure(t *testing.T) {
// rolled back.
if err := <-errCh; err != nil {
t.Logf("%s failed, checking that imported data was completely removed: %q", query, err)
sqlDB.CheckQueryResults(t, `SELECT * FROM t ORDER BY i`, [][]string{})
sqlDB.CheckQueryResultsRetry(t, `SELECT * FROM t ORDER BY i`, [][]string{})
return
}

// But the job should be restarted and succeed eventually.
jobutils.WaitForJobToSucceed(t, sqlDB, jobID)
sqlDB.CheckQueryResults(t,
sqlDB.CheckQueryResultsRetry(t,
`SELECT * FROM t ORDER BY i`,
sqlDB.QueryStr(t, `SELECT * FROM generate_series(0, $1)`, count-1),
)
Expand Down

0 comments on commit 748e9f1

Please sign in to comment.