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
36 changes: 34 additions & 2 deletions src/iceberg/test/util/docker_compose_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@

#include "iceberg/test/util/docker_compose_util.h"

#include <chrono>
#include <print>
#include <stdexcept>
#include <thread>

#include "iceberg/test/util/cmd_util.h"

namespace iceberg {

namespace {

// Compose pulls the fixture image from Docker Hub on every run, and that request
// intermittently times out on CI runners.
constexpr int kUpMaxAttempts = 3;
constexpr std::chrono::seconds kUpRetryBackoff{5};

} // namespace

DockerCompose::DockerCompose(std::string project_name,
std::filesystem::path docker_compose_dir)
: project_name_(std::move(project_name)),
Expand All @@ -31,8 +45,26 @@ DockerCompose::DockerCompose(std::string project_name,
DockerCompose::~DockerCompose() { Down(); }

void DockerCompose::Up() {
auto cmd = BuildDockerCommand({"up", "-d", "--wait", "--timeout", "60"});
return cmd.RunCommand("docker compose up");
for (int attempt = 1;; ++attempt) {
try {
auto cmd = BuildDockerCommand({"up", "-d", "--wait", "--timeout", "60"});
cmd.RunCommand("docker compose up");
return;
} catch (const std::runtime_error&) {
if (attempt >= kUpMaxAttempts) {
throw;
}
std::println(stderr, "[INFO] docker compose up attempt {}/{} failed, retrying",
attempt, kUpMaxAttempts);
try {
Down();
} catch (const std::runtime_error&) {
// Nothing worth reporting: the retry re-runs up either way, and the
// original failure is what surfaces if attempts run out.
}
std::this_thread::sleep_for(kUpRetryBackoff * attempt);
}
}
}

void DockerCompose::Down() {
Expand Down
4 changes: 2 additions & 2 deletions src/iceberg/test/util/docker_compose_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class DockerCompose {
/// \brief Get the docker project name.
const std::string& project_name() const { return project_name_; }

/// \brief Executes 'docker-compose up' to start services.
/// \note May throw an exception if the services fail to start.
/// \brief Executes 'docker-compose up' to start services, retrying on failure.
/// \note May throw an exception if every attempt fails to start the services.
void Up();

/// \brief Executes 'docker-compose down' to stop and remove services.
Expand Down
Loading