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))); } }
/** * @covers Guzzle\Http\Plugin\ExponentialBackoffPlugin::onRequestSent */ public function testExponentiallyBacksOffCurlErrors() { $plugin = $this->getMock('Guzzle\\Http\\Plugin\\ExponentialBackoffPlugin', array('retryRequest')); // Mock the retryRequest method so that it does nothing, but ensure // that it is called exactly once $plugin->expects($this->once())->method('retryRequest')->will($this->returnValue(null)); // Create an exception that is found in the default curl exception list $exception = new CurlException('Curl'); $exception->setError('foo', CURLE_OPERATION_TIMEOUTED); // Create a dummy event to send to the plugin $event = new Event(array('request' => new Request('GET', 'http://test.com'), 'response' => null, 'exception' => $exception)); // Ensure the it uses the name we're looking for $event->setName('request.exception'); // Trigger the event $plugin->onRequestSent($event); }