Google\Cloud\Tests\ExponentialBackoffTest::testThrowsExceptionWhenRetryFunctionReturnsFalse PHP Method

testThrowsExceptionWhenRetryFunctionReturnsFalse() public method

    public function testThrowsExceptionWhenRetryFunctionReturnsFalse()
    {
        $actualAttempts = 0;
        $hasTriggeredException = false;
        $retryFunction = function (\Exception $ex) {
            return false;
        };
        $backoff = new ExponentialBackoff(null, $retryFunction);
        $backoff->setDelayFunction($this->delayFunction);
        try {
            $backoff->execute(function () use(&$actualAttempts) {
                $actualAttempts++;
                throw new \Exception();
            });
        } catch (\Exception $ex) {
            $hasTriggeredException = true;
        }
        $this->assertTrue($hasTriggeredException);
        $this->assertEquals(1, $actualAttempts);
    }