Skip to content

Commit

Permalink
gcjob_test: fix logging in TestGCJobRetry
Browse files Browse the repository at this point in the history
This patch fixes the logging in `TestGCJobRetry` to handle NULL values
being returned by a query.

Release note: None
  • Loading branch information
andyyang890 committed Oct 9, 2023
1 parent dd94a14 commit 4a58cba
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/sql/gcjob_test/gc_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package gcjob_test

import (
"context"
gosql "database/sql"
"fmt"
"strconv"
"sync/atomic"
Expand Down Expand Up @@ -320,18 +321,22 @@ SELECT job_id

const expectedRunningStatus = string(sql.RunningStatusWaitingForMVCCGC)
testutils.SucceedsSoon(t, func() error {
var status, runningStatus, lastRun, nextRun, numRuns, jobErr string
var status, runningStatus, lastRun, nextRun, numRuns, jobErr gosql.NullString
tdb.QueryRow(t, fmt.Sprintf(`
SELECT status, running_status, error, last_run, next_run, num_runs
FROM crdb_internal.jobs
WHERE job_id = %s`, jobID)).Scan(&status, &runningStatus, &jobErr, &lastRun, &nextRun, &numRuns)

t.Logf(`details about SCHEMA CHANGE GC job: {status: %q, running_status: %q, error: %q, last_run: %q, next_run: %q, num_runs: %q}`,
t.Logf(`details about SCHEMA CHANGE GC job: {status: %#v, running_status: %#v, error: %#v, last_run: %#v, next_run: %#v, num_runs: %#v}`,
status, runningStatus, jobErr, lastRun, nextRun, numRuns)

if runningStatus != expectedRunningStatus {
return errors.Newf(`running_status %s does not match expected status %s`,
runningStatus, expectedRunningStatus)
if !runningStatus.Valid {
return errors.Newf(`running_status is NULL but expected %q`, expectedRunningStatus)
}

if actualRunningStatus := runningStatus.String; actualRunningStatus != expectedRunningStatus {
return errors.Newf(`running_status %q does not match expected status %q`,
actualRunningStatus, expectedRunningStatus)
}

return nil
Expand Down

0 comments on commit 4a58cba

Please sign in to comment.