Skip to content

Commit 2076293

Browse files
authored
Merge pull request #199 from ByteInternet/catch-server-exceptions-brancher-logbook
Catch HypernodeApiServerException in brancher polling
2 parents 8ef63d0 + 0b117e7 commit 2076293

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎src/Brancher/BrancherHypernodeManager.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ public function waitForAvailability(
202202
$resolved = true;
203203
break;
204204
}
205-
} catch (HypernodeApiClientException $e) {
205+
} catch (HypernodeApiClientException | HypernodeApiServerException $e) {
206206
// A 404 not found means there are no flows in the logbook yet, we should wait.
207207
// Otherwise, there's an error, and it should be propagated.
208-
if ($e->getCode() !== 404) {
208+
if (!in_array($e->getCode(), [404, 502])) {
209209
throw $e;
210210
} elseif (($timeElapsed - $logbookStartTime) < $allowedErrorWindow) {
211211
// Sometimes we get an error where the logbook is not yet available, but it will be soon.

‎src/DeployRunner.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Deployer\Exception\GracefulShutdownException;
88
use Deployer\Host\Host;
99
use Deployer\Task\Task;
10+
use Hypernode\Api\Exception\HypernodeApiServerException;
1011
use Hypernode\Deploy\Brancher\BrancherHypernodeManager;
1112
use Hypernode\Deploy\Deployer\RecipeLoader;
1213
use Hypernode\Deploy\Deployer\Task\ConfigurableTaskInterface;
@@ -313,7 +314,7 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche
313314
$reachabilityCheckInterval
314315
);
315316
$this->log->info('Brancher Hypernode has become available!');
316-
} catch (CreateBrancherHypernodeFailedException | TimeoutException $e) {
317+
} catch (CreateBrancherHypernodeFailedException | TimeoutException | HypernodeApiServerException $e) {
317318
if (in_array($brancherApp, $this->brancherHypernodesRegistered)) {
318319
$this->brancherHypernodeManager->cancel($brancherApp);
319320
}

‎tests/Unit/Brancher/BrancherHypernodeManagerTest.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Hypernode\Deploy\Tests\Unit\Brancher;
66

77
use Hypernode\Api\Exception\HypernodeApiClientException;
8+
use Hypernode\Api\Exception\HypernodeApiServerException;
89
use Hypernode\Api\HypernodeClient;
910
use Hypernode\Api\Resource\Logbook\Flow;
1011
use Hypernode\Api\Service\BrancherApp;
@@ -165,6 +166,25 @@ public function testLogbookNon404ErrorPropagates(): void
165166
$this->manager->waitForAvailability('test-brancher', 1500, 6, 10);
166167
}
167168

169+
public function testLogbookServerErrorPropagates(): void
170+
{
171+
$this->sshPoller->pollResults = array_fill(0, 5, false);
172+
173+
$response = $this->createMock(ResponseInterface::class);
174+
$response->method('getStatusCode')->willReturn(503);
175+
$response->method('getBody')->willReturn('Service Unavailable');
176+
$exception503 = new HypernodeApiServerException($response);
177+
178+
$this->logbook->expects($this->once())
179+
->method('getList')
180+
->with('test-brancher')
181+
->willThrowException($exception503);
182+
183+
$this->expectException(HypernodeApiServerException::class);
184+
185+
$this->manager->waitForAvailability('test-brancher', 1500, 6, 10);
186+
}
187+
168188
public function testSshFirstCheckIntermittentFailuresResetCounter(): void
169189
{
170190
$this->sshPoller->pollResults = [true, true, false, true, true, true];

0 commit comments

Comments
 (0)