func waitForJob(t *testing.T, jobAPIClient pps.JobAPIClient, job *pps.Job, timeoutSec int, expectError bool) *pps.JobInfo { for i := 0; i < timeoutSec; i++ { time.Sleep(1 * time.Second) jobInfo, err := jobAPIClient.InspectJob( context.Background(), &pps.InspectJobRequest{ Job: job, }, ) require.NoError(t, err) if len(jobInfo.JobStatus) == 0 { continue } jobStatus := jobInfo.JobStatus[0] protolog.Infof("status of job %s at %d seconds: %v", job.Id, i+1, jobInfo.JobStatus) switch jobStatus.Type { case pps.JobStatusType_JOB_STATUS_TYPE_ERROR: handleEndJobStatus(t, jobAPIClient, jobInfo) if !expectError { t.Fatalf("job %s had error", job.Id) } return jobInfo case pps.JobStatusType_JOB_STATUS_TYPE_SUCCESS: handleEndJobStatus(t, jobAPIClient, jobInfo) if expectError { t.Fatalf("job %s did not have error", job.Id) } return jobInfo } } t.Fatalf("job %s did not finish in %d seconds", job.Id, timeoutSec) return nil }