Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Brancher/BrancherHypernodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($e->getCode() !== 404) {
if (!in_array($e->getCode(), [404, 502])) {

A 502 basically in this case means a temporary service disruption, I think we should allow it.

Expand Down
3 changes: 2 additions & 1 deletion src/DeployRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/Brancher/BrancherHypernodeManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
Loading