Skip to content

Commit 15c57e6

Browse files
authored
Merge pull request #8 from keboola/adamvyborny-COM-1354-log-retry-as-info
Change retry log level to info
2 parents 779f29f + 61f7073 commit 15c57e6

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/Google/RestApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ protected function logRetryRequest(
302302
];
303303
}
304304

305-
$this->logger->warning(sprintf('Retrying request (%sx)', $retries), $context);
305+
$this->logger->info(sprintf('Retrying request (%sx)', $retries), $context);
306306
}
307307
}
308308

tests/RestApiTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Keboola\Google\ClientBundle\Tests;
66

7+
use GuzzleHttp\Exception\ClientException;
78
use Keboola\Google\ClientBundle\Google\RestApi;
9+
use Monolog\Handler\TestHandler;
810
use Monolog\Logger;
911
use PHPUnit\Framework\TestCase;
1012
use SebastianBergmann\Timer\Timer;
@@ -23,12 +25,17 @@ class RestApiTest extends TestCase
2325
/** @var Logger */
2426
private $logger;
2527

28+
/** @var TestHandler */
29+
private $testHandler;
30+
2631
protected function initApi(): RestApi
2732
{
2833
$this->clientId = $this->getEnv('CLIENT_ID');
2934
$this->clientSecret = $this->getEnv('CLIENT_SECRET');
3035
$this->refreshToken = $this->getEnv('REFRESH_TOKEN');
36+
$this->testHandler = new TestHandler();
3137
$this->logger = new Logger('Google Rest API tests');
38+
$this->logger->pushHandler($this->testHandler);
3239

3340
return new RestApi(
3441
$this->clientId,
@@ -99,6 +106,22 @@ public function testDelayFn(): void
99106
$this->assertGreaterThan(5, $time);
100107
}
101108

109+
public function testRetries(): void
110+
{
111+
$restApi = $this->initApi();
112+
try {
113+
$restApi->request('/auth/invalid-scope');
114+
} catch (ClientException $e) {
115+
}
116+
117+
$this->assertNotCount(0, $this->testHandler->getRecords());
118+
119+
foreach ($this->testHandler->getRecords() as $key => $value) {
120+
$this->assertEquals(Logger::INFO, $value['level']);
121+
$this->assertEquals(sprintf('Retrying request (%dx)', $key), $value['message']);
122+
}
123+
}
124+
102125
protected function getEnv(string $name): string
103126
{
104127
$value = getenv($name);

0 commit comments

Comments
 (0)