diff --git a/src/Client.php b/src/Client.php index 05d4ad9..6fa98f0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -360,6 +360,7 @@ public function waitForJobCompletion(string $queryJobId, int $maxWaitSeconds = 3 { $startTime = time(); + $tries = 0; while (time() - $startTime < $maxWaitSeconds) { $status = $this->getJobStatus($queryJobId); @@ -367,7 +368,10 @@ public function waitForJobCompletion(string $queryJobId, int $maxWaitSeconds = 3 return $status; } - sleep(1); + // 60, 70, 90, 130, 210, 370, 690, 1000ms (max) + $waitMilliseconds = min(50+pow(2, $tries)*10, 1000); + usleep($waitMilliseconds * 1000); + $tries++; } throw new ClientException( diff --git a/tests/Functional/QueryServiceFunctionalTest.php b/tests/Functional/QueryServiceFunctionalTest.php index 6f19594..9d704a5 100644 --- a/tests/Functional/QueryServiceFunctionalTest.php +++ b/tests/Functional/QueryServiceFunctionalTest.php @@ -127,22 +127,12 @@ public function testSubmitTransactionalQuery(): void public function testCancelQueryJob(): void { - // Create test table - $tableName = $this->createTestTable(); - - // Submit a cross join query that takes some time to process $response = $this->queryClient->submitQueryJob( $this->getTestBranchId(), $this->getTestWorkspaceId(), [ 'statements' => [ - sprintf(' - SELECT a.id, b.id as id2, a.name, b.name as name2 - FROM %s a - CROSS JOIN %s b - CROSS JOIN %s c - ORDER BY 1, 2 - ', $tableName, $tableName, $tableName), + 'CALL SYSTEM$WAIT(10);', // Wait for 10 seconds to allow time for cancellation ], 'transactional' => false, ],