From 4a58cbac044b13b4744cde6efbf40f0043239872 Mon Sep 17 00:00:00 2001 From: Andy Yang Date: Mon, 9 Oct 2023 00:29:48 -0400 Subject: [PATCH] gcjob_test: fix logging in TestGCJobRetry This patch fixes the logging in `TestGCJobRetry` to handle NULL values being returned by a query. Release note: None --- pkg/sql/gcjob_test/gc_job_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/sql/gcjob_test/gc_job_test.go b/pkg/sql/gcjob_test/gc_job_test.go index 131bce71aeb3..8d230491b798 100644 --- a/pkg/sql/gcjob_test/gc_job_test.go +++ b/pkg/sql/gcjob_test/gc_job_test.go @@ -12,6 +12,7 @@ package gcjob_test import ( "context" + gosql "database/sql" "fmt" "strconv" "sync/atomic" @@ -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