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

testThrowsExceptionAfterFullAttempts() public method

public testThrowsExceptionAfterFullAttempts ( $retries, $exception )
    public function testThrowsExceptionAfterFullAttempts($retries, $exception)
    {
        // Expected attempts is the number of retries plus the initial attempt.
        $expectedAttempts = $retries ? $retries + 1 : 4;
        $actualAttempts = 0;
        $hasTriggeredException = false;
        $backoff = new ExponentialBackoff($retries);
        $backoff->setDelayFunction($this->delayFunction);
        try {
            $backoff->execute(function () use(&$actualAttempts, $expectedAttempts, $exception) {
                $actualAttempts++;
                throw $exception;
            });
        } catch (\Exception $ex) {
            $hasTriggeredException = true;
        }
        $this->assertTrue($hasTriggeredException);
        $this->assertEquals($expectedAttempts, $actualAttempts);
    }