1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
<?php
namespace Guzzle\Tests\Plugin\Backoff;
use Guzzle\Http\Message\Response;
use Guzzle\Plugin\Backoff\CurlBackoffStrategy;
use Guzzle\Http\Exception\CurlException;
class CurlBackoffStrategyTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testRetriesWithExponentialDelay()
{
$this->assertNotEmpty(CurlBackoffStrategy::getDefaultFailureCodes());
$strategy = new CurlBackoffStrategy();
$this->assertTrue($strategy->makesDecision());
$request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false);
$e = new CurlException();
$e->setError('foo', CURLE_BAD_CALLING_ORDER);
$this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, null, $e));
foreach (CurlBackoffStrategy::getDefaultFailureCodes() as $code) {
$this->assertEquals(0, $strategy->getBackoffPeriod(0, $request, null, $e->setError('foo', $code)));
}
}
public function testIgnoresNonErrors()
{
$strategy = new CurlBackoffStrategy();
$request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false);
$this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, new Response(200)));
}
}