diff --git a/src/Brancher/BrancherHypernodeManager.php b/src/Brancher/BrancherHypernodeManager.php index 394c34e..13e7dd9 100644 --- a/src/Brancher/BrancherHypernodeManager.php +++ b/src/Brancher/BrancherHypernodeManager.php @@ -202,7 +202,7 @@ public function waitForAvailability( $resolved = true; break; } - } catch (HypernodeApiClientException $e) { + } catch (HypernodeApiClientException | HypernodeApiServerException $e) { // A 404 not found means there are no flows in the logbook yet, we should wait. // Otherwise, there's an error, and it should be propagated. if ($e->getCode() !== 404) { diff --git a/src/DeployRunner.php b/src/DeployRunner.php index 4bb2b15..f12f32c 100644 --- a/src/DeployRunner.php +++ b/src/DeployRunner.php @@ -7,6 +7,7 @@ use Deployer\Exception\GracefulShutdownException; use Deployer\Host\Host; use Deployer\Task\Task; +use Hypernode\Api\Exception\HypernodeApiServerException; use Hypernode\Deploy\Brancher\BrancherHypernodeManager; use Hypernode\Deploy\Deployer\RecipeLoader; use Hypernode\Deploy\Deployer\Task\ConfigurableTaskInterface; @@ -313,7 +314,7 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche $reachabilityCheckInterval ); $this->log->info('Brancher Hypernode has become available!'); - } catch (CreateBrancherHypernodeFailedException | TimeoutException $e) { + } catch (CreateBrancherHypernodeFailedException | TimeoutException | HypernodeApiServerException $e) { if (in_array($brancherApp, $this->brancherHypernodesRegistered)) { $this->brancherHypernodeManager->cancel($brancherApp); } diff --git a/tests/Unit/Brancher/BrancherHypernodeManagerTest.php b/tests/Unit/Brancher/BrancherHypernodeManagerTest.php index e226410..50aa1fa 100644 --- a/tests/Unit/Brancher/BrancherHypernodeManagerTest.php +++ b/tests/Unit/Brancher/BrancherHypernodeManagerTest.php @@ -5,6 +5,7 @@ namespace Hypernode\Deploy\Tests\Unit\Brancher; use Hypernode\Api\Exception\HypernodeApiClientException; +use Hypernode\Api\Exception\HypernodeApiServerException; use Hypernode\Api\HypernodeClient; use Hypernode\Api\Resource\Logbook\Flow; use Hypernode\Api\Service\BrancherApp; @@ -165,6 +166,25 @@ public function testLogbookNon404ErrorPropagates(): void $this->manager->waitForAvailability('test-brancher', 1500, 6, 10); } + public function testLogbookServerErrorPropagates(): void + { + $this->sshPoller->pollResults = array_fill(0, 5, false); + + $response = $this->createMock(ResponseInterface::class); + $response->method('getStatusCode')->willReturn(503); + $response->method('getBody')->willReturn('Service Unavailable'); + $exception503 = new HypernodeApiServerException($response); + + $this->logbook->expects($this->once()) + ->method('getList') + ->with('test-brancher') + ->willThrowException($exception503); + + $this->expectException(HypernodeApiServerException::class); + + $this->manager->waitForAvailability('test-brancher', 1500, 6, 10); + } + public function testSshFirstCheckIntermittentFailuresResetCounter(): void { $this->sshPoller->pollResults = [true, true, false, true, true, true];