public function testUpdatesRequestForRetry() { $request = new Request('GET', 'http://www.example.com'); $request->setState('transfer'); $response = new Response(500); $handle = $this->getMockBuilder('Guzzle\\Http\\Curl\\CurlHandle')->disableOriginalConstructor()->getMock(); $e = new CurlException(); $e->setCurlHandle($handle); $plugin = new BackoffPlugin(new ConstantBackoffStrategy(10)); $plugin->addSubscriber($this); $event = new Event(array('request' => $request, 'response' => $response, 'exception' => $e)); $plugin->onRequestSent($event); $this->assertEquals(array('request' => $request, 'response' => $response, 'handle' => $handle, 'retries' => 1, 'delay' => 10), $this->readAttribute($this->retried, 'context')); $plugin->onRequestSent($event); $this->assertEquals(array('request' => $request, 'response' => $response, 'handle' => $handle, 'retries' => 2, 'delay' => 10), $this->readAttribute($this->retried, 'context')); }
/** * Check if a cURL transfer resulted in what should be an exception * * @param RequestInterface $request Request to check * @param CurlHandle $handle Curl handle object * @param array $curl Array returned from curl_multi_info_read * * @return CurlException|bool */ private function isCurlException(RequestInterface $request, CurlHandle $handle, array $curl) { if (CURLM_OK == $curl['result'] || CURLM_CALL_MULTI_PERFORM == $curl['result']) { return false; } $handle->setErrorNo($curl['result']); $e = new CurlException(sprintf('[curl] %s: %s [url] %s', $handle->getErrorNo(), $handle->getError(), $handle->getUrl())); $e->setCurlHandle($handle)->setRequest($request)->setCurlInfo($handle->getInfo())->setError($handle->getError(), $handle->getErrorNo()); return $e; }
/** * Check if a cURL transfer resulted in what should be an exception * * @param RequestInterface $request Request to check * @param CurlHandle $handle Curl handle object * @param array $curl Array returned from curl_multi_info_read * * @return \Exception|bool */ private function isCurlException(RequestInterface $request, CurlHandle $handle, array $curl) { if (CURLE_OK == $curl['result']) { return false; } $handle->setErrorNo($curl['result']); $e = new CurlException(sprintf('[curl] %s: %s [url] %s [info] %s [debug] %s', $handle->getErrorNo(), $handle->getError(), $handle->getUrl(), var_export($handle->getInfo(), true), $handle->getStderr())); $e->setCurlHandle($handle)->setRequest($request)->setError($handle->getError(), $handle->getErrorNo()); return $e; }