ReloadableApplications: supervised out-of-process provider with bounded restart policy and explicit unknown effects (P-RELOADABLE-06)
This commit is contained in:
1 parent
aad91c7d01
commit
9ba4738415
6 files changed
+611
-3
No files matched your search
@@ -5,17 +5,19 @@ set(CMAKE_CXX_STANDARD 26)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS Functional)
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS Functional System)
|
||||
|
||||
add_library(reloadable_host STATIC
|
||||
src/activation.cpp
|
||||
src/checkpoint.cpp
|
||||
src/control.cpp
|
||||
src/posix_worker.cpp
|
||||
src/release_registry.cpp
|
||||
src/reload_transaction.cpp
|
||||
src/resources.cpp)
|
||||
src/resources.cpp
|
||||
src/supervisor.cpp)
|
||||
target_include_directories(reloadable_host PUBLIC include)
|
||||
target_link_libraries(reloadable_host PUBLIC Void::Functional)
|
||||
target_link_libraries(reloadable_host PUBLIC Void::Functional Void::System)
|
||||
|
||||
add_executable(reloadable_host_test tests/reload_transaction_test.cpp)
|
||||
target_link_libraries(reloadable_host_test PRIVATE reloadable_host)
|
||||
@@ -35,6 +37,9 @@ target_link_libraries(reloadable_host_activation_test PRIVATE reloadable_host)
|
||||
add_executable(reloadable_host_failure_matrix_test tests/reload_failure_matrix_test.cpp)
|
||||
target_link_libraries(reloadable_host_failure_matrix_test PRIVATE reloadable_host)
|
||||
|
||||
add_executable(reloadable_host_supervisor_test tests/supervisor_test.cpp)
|
||||
target_link_libraries(reloadable_host_supervisor_test PRIVATE reloadable_host)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME reloadable_host_transaction COMMAND reloadable_host_test)
|
||||
add_test(NAME reloadable_host_release COMMAND reloadable_host_release_test)
|
||||
@@ -42,3 +47,4 @@ add_test(NAME reloadable_host_control COMMAND reloadable_host_control_test)
|
||||
add_test(NAME reloadable_host_checkpoint COMMAND reloadable_host_checkpoint_test)
|
||||
add_test(NAME reloadable_host_activation COMMAND reloadable_host_activation_test)
|
||||
add_test(NAME reloadable_host_failure_matrix COMMAND reloadable_host_failure_matrix_test)
|
||||
add_test(NAME reloadable_host_supervisor COMMAND reloadable_host_supervisor_test)
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "reloadable_host/supervisor.hpp"
|
||||
|
||||
#include <Void/System/Process.hpp>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace ReloadableHost
|
||||
{
|
||||
/// Real out-of-process provider port over Void::Process.
|
||||
///
|
||||
/// Commands run through `/bin/sh -c` with inherited stdio (no unconsumed
|
||||
/// pipes), so a noisy worker cannot fill an unread pipe and block.
|
||||
class PosixWorkerPort final : public WorkerProcessPort
|
||||
{
|
||||
public:
|
||||
|
||||
PosixWorkerPort() = default;
|
||||
PosixWorkerPort(const PosixWorkerPort&) = delete;
|
||||
PosixWorkerPort& operator=(const PosixWorkerPort&) = delete;
|
||||
~PosixWorkerPort() override;
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
spawn(const std::string& command) override;
|
||||
|
||||
[[nodiscard]] Void::Result::Result<std::optional<WorkerExit>>
|
||||
try_wait() override;
|
||||
|
||||
void terminate(std::chrono::milliseconds grace) noexcept override;
|
||||
|
||||
[[nodiscard]] bool running() const noexcept override;
|
||||
|
||||
private:
|
||||
|
||||
std::optional<Void::Process::Child> m_child{};
|
||||
};
|
||||
} // namespace ReloadableHost
|
||||
@@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Functional/Result.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace ReloadableHost
|
||||
{
|
||||
enum class WorkerState : std::uint8_t {
|
||||
Stopped,
|
||||
Running,
|
||||
Restarting,
|
||||
Failed
|
||||
};
|
||||
|
||||
/// Effects already handed to a crashed worker cannot be proven absent.
|
||||
enum class EffectState : std::uint8_t {
|
||||
None,
|
||||
InProgress,
|
||||
/// The worker died (or was terminated) with an effect in progress.
|
||||
/// The host must reconcile with the provider; it must never assume
|
||||
/// the effect was rolled back.
|
||||
Unknown,
|
||||
Completed
|
||||
};
|
||||
|
||||
struct RestartPolicy {
|
||||
std::uint32_t max_restarts{3};
|
||||
std::chrono::milliseconds base_backoff{50};
|
||||
std::chrono::milliseconds max_backoff{1000};
|
||||
};
|
||||
|
||||
struct WorkerExit {
|
||||
bool exited{false};
|
||||
int code{-1};
|
||||
int signal{0};
|
||||
|
||||
[[nodiscard]] bool clean() const noexcept
|
||||
{
|
||||
return exited && code == 0 && signal == 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct SupervisorReport {
|
||||
WorkerState state{WorkerState::Stopped};
|
||||
EffectState effects{EffectState::None};
|
||||
std::uint32_t restarts{0};
|
||||
/// Advisory delay before the next restart attempt; the caller
|
||||
/// owns the clock so supervision stays deterministic.
|
||||
std::chrono::milliseconds next_backoff{0};
|
||||
std::string last_error;
|
||||
};
|
||||
|
||||
/// Spawn/observe/terminate boundary for one out-of-process provider.
|
||||
/// Implementations own exactly one worker at a time.
|
||||
class WorkerProcessPort
|
||||
{
|
||||
public:
|
||||
|
||||
WorkerProcessPort() = default;
|
||||
WorkerProcessPort(const WorkerProcessPort&) = delete;
|
||||
WorkerProcessPort& operator=(const WorkerProcessPort&) = delete;
|
||||
virtual ~WorkerProcessPort() = default;
|
||||
|
||||
[[nodiscard]] virtual Void::Result::Result<void>
|
||||
spawn(const std::string& command) = 0;
|
||||
|
||||
/// Non-blocking observation. Empty optional while still running.
|
||||
[[nodiscard]] virtual Void::Result::Result<
|
||||
std::optional<WorkerExit>>
|
||||
try_wait() = 0;
|
||||
|
||||
virtual void terminate(std::chrono::milliseconds grace) noexcept = 0;
|
||||
[[nodiscard]] virtual bool running() const noexcept = 0;
|
||||
};
|
||||
|
||||
/// Supervises one out-of-process provider with an explicit restart policy.
|
||||
///
|
||||
/// Restarts are attempted only by the next `poll()` after a crash, so the
|
||||
/// backoff is reported rather than slept. A crash with an in-progress
|
||||
/// effect reports `EffectState::Unknown`: this composition makes no
|
||||
/// exactly-once or distributed claim.
|
||||
class WorkerSupervisor
|
||||
{
|
||||
public:
|
||||
|
||||
WorkerSupervisor(WorkerProcessPort& port, std::string command,
|
||||
RestartPolicy policy = {});
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void> start();
|
||||
|
||||
/// Mark one effect as handed to the worker, and its confirmed
|
||||
/// completion.
|
||||
void begin_effect() noexcept;
|
||||
void complete_effect() noexcept;
|
||||
|
||||
/// Observe one exit (non-blocking) and apply the restart policy.
|
||||
/// The next poll after a crash respawns the worker.
|
||||
[[nodiscard]] Void::Result::Result<SupervisorReport> poll();
|
||||
|
||||
/// Terminate a running worker with a bounded grace. Never claims an
|
||||
/// in-progress effect was rolled back.
|
||||
void stop(std::chrono::milliseconds grace = std::chrono::milliseconds{
|
||||
2000}) noexcept;
|
||||
|
||||
[[nodiscard]] SupervisorReport report() const;
|
||||
|
||||
private:
|
||||
|
||||
[[nodiscard]] std::chrono::milliseconds backoff_for(
|
||||
std::uint32_t restarts) const noexcept;
|
||||
|
||||
WorkerProcessPort& m_port;
|
||||
std::string m_command;
|
||||
RestartPolicy m_policy;
|
||||
SupervisorReport m_report{};
|
||||
};
|
||||
} // namespace ReloadableHost
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "reloadable_host/posix_worker.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace ReloadableHost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
[[nodiscard]] Void::Result::Error state_error(std::string message)
|
||||
{
|
||||
return Void::Result::Error{Void::Result::ErrorKind::conflict,
|
||||
std::move(message)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
PosixWorkerPort::~PosixWorkerPort()
|
||||
{
|
||||
if (m_child && m_child->valid()) {
|
||||
(void)m_child->terminate(std::chrono::milliseconds{2000});
|
||||
}
|
||||
}
|
||||
|
||||
Void::Result::Result<void>
|
||||
PosixWorkerPort::spawn(const std::string& command)
|
||||
{
|
||||
if (m_child && m_child->valid() && m_child->running()) {
|
||||
return std::unexpected{
|
||||
state_error("PosixWorkerPort: a worker is already running")};
|
||||
}
|
||||
m_child.reset();
|
||||
|
||||
Void::Process::SpawnOptions options;
|
||||
options.executable = "/bin/sh";
|
||||
options.arguments = {"-c", command};
|
||||
options.stdin_pipe = false;
|
||||
options.stdout_pipe = false;
|
||||
options.stderr_pipe = false;
|
||||
auto child = Void::Process::spawn(options);
|
||||
if (!child) {
|
||||
return std::unexpected{std::move(child).error()};
|
||||
}
|
||||
m_child.emplace(std::move(*child));
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<std::optional<WorkerExit>> PosixWorkerPort::try_wait()
|
||||
{
|
||||
if (!m_child) {
|
||||
return std::optional<WorkerExit>{};
|
||||
}
|
||||
auto status = m_child->try_wait();
|
||||
if (!status) {
|
||||
return std::unexpected{std::move(status).error()};
|
||||
}
|
||||
if (!status->has_value()) {
|
||||
return std::optional<WorkerExit>{};
|
||||
}
|
||||
const auto& exit = **status;
|
||||
return std::optional<WorkerExit>{WorkerExit{
|
||||
.exited = exit.exited, .code = exit.code, .signal = exit.signal}};
|
||||
}
|
||||
|
||||
void PosixWorkerPort::terminate(std::chrono::milliseconds grace) noexcept
|
||||
{
|
||||
if (m_child && m_child->valid()) {
|
||||
(void)m_child->terminate(grace);
|
||||
}
|
||||
}
|
||||
|
||||
bool PosixWorkerPort::running() const noexcept
|
||||
{
|
||||
return m_child && m_child->running();
|
||||
}
|
||||
} // namespace ReloadableHost
|
||||
@@ -0,0 +1,148 @@
|
||||
#include "reloadable_host/supervisor.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace ReloadableHost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
[[nodiscard]] Void::Result::Error state_error(std::string message)
|
||||
{
|
||||
return Void::Result::Error{Void::Result::ErrorKind::conflict,
|
||||
std::move(message)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
WorkerSupervisor::WorkerSupervisor(WorkerProcessPort& port,
|
||||
std::string command,
|
||||
RestartPolicy policy)
|
||||
: m_port(port), m_command(std::move(command)), m_policy(policy)
|
||||
{
|
||||
}
|
||||
|
||||
std::chrono::milliseconds
|
||||
WorkerSupervisor::backoff_for(std::uint32_t restarts) const noexcept
|
||||
{
|
||||
if (restarts == 0) {
|
||||
return std::chrono::milliseconds{0};
|
||||
}
|
||||
auto delay = m_policy.base_backoff;
|
||||
for (std::uint32_t i = 1; i < restarts; ++i) {
|
||||
if (delay >= m_policy.max_backoff) {
|
||||
break;
|
||||
}
|
||||
delay *= 2;
|
||||
}
|
||||
return std::min(delay, m_policy.max_backoff);
|
||||
}
|
||||
|
||||
Void::Result::Result<void> WorkerSupervisor::start()
|
||||
{
|
||||
if (m_report.state == WorkerState::Running) {
|
||||
return std::unexpected{
|
||||
state_error("WorkerSupervisor: already running")};
|
||||
}
|
||||
if (m_report.state == WorkerState::Failed) {
|
||||
return std::unexpected{state_error(
|
||||
"WorkerSupervisor: restart budget exhausted; recreate")};
|
||||
}
|
||||
if (auto spawned = m_port.spawn(m_command); !spawned) {
|
||||
m_report.state = WorkerState::Failed;
|
||||
m_report.last_error = spawned.error().message();
|
||||
return spawned;
|
||||
}
|
||||
m_report.state = WorkerState::Running;
|
||||
m_report.next_backoff = std::chrono::milliseconds{0};
|
||||
return {};
|
||||
}
|
||||
|
||||
void WorkerSupervisor::begin_effect() noexcept
|
||||
{
|
||||
if (m_report.effects != EffectState::Unknown) {
|
||||
m_report.effects = EffectState::InProgress;
|
||||
}
|
||||
}
|
||||
|
||||
void WorkerSupervisor::complete_effect() noexcept
|
||||
{
|
||||
if (m_report.effects == EffectState::InProgress) {
|
||||
m_report.effects = EffectState::Completed;
|
||||
}
|
||||
}
|
||||
|
||||
Void::Result::Result<SupervisorReport> WorkerSupervisor::poll()
|
||||
{
|
||||
if (m_report.state == WorkerState::Restarting) {
|
||||
if (auto spawned = m_port.spawn(m_command); !spawned) {
|
||||
m_report.state = WorkerState::Failed;
|
||||
m_report.last_error = spawned.error().message();
|
||||
return std::unexpected{std::move(spawned).error()};
|
||||
}
|
||||
m_report.state = WorkerState::Running;
|
||||
m_report.next_backoff = std::chrono::milliseconds{0};
|
||||
return m_report;
|
||||
}
|
||||
if (m_report.state != WorkerState::Running) {
|
||||
return m_report;
|
||||
}
|
||||
|
||||
auto observed = m_port.try_wait();
|
||||
if (!observed) {
|
||||
m_report.state = WorkerState::Failed;
|
||||
m_report.last_error = observed.error().message();
|
||||
return std::unexpected{std::move(observed).error()};
|
||||
}
|
||||
if (!observed->has_value()) {
|
||||
return m_report; // still running
|
||||
}
|
||||
const WorkerExit exit = **observed;
|
||||
|
||||
if (exit.clean()) {
|
||||
m_report.state = WorkerState::Stopped;
|
||||
if (m_report.effects == EffectState::InProgress) {
|
||||
// Clean exit is not proof the effect completed.
|
||||
m_report.effects = EffectState::Unknown;
|
||||
}
|
||||
return m_report;
|
||||
}
|
||||
|
||||
// Crash or signal: an in-progress effect has an unknown outcome.
|
||||
if (m_report.effects == EffectState::InProgress) {
|
||||
m_report.effects = EffectState::Unknown;
|
||||
}
|
||||
m_report.last_error =
|
||||
exit.signal != 0
|
||||
? "worker terminated by signal " + std::to_string(exit.signal)
|
||||
: "worker exited with code " + std::to_string(exit.code);
|
||||
|
||||
if (m_report.restarts >= m_policy.max_restarts) {
|
||||
m_report.state = WorkerState::Failed;
|
||||
m_report.next_backoff = std::chrono::milliseconds{0};
|
||||
return m_report;
|
||||
}
|
||||
++m_report.restarts;
|
||||
m_report.state = WorkerState::Restarting;
|
||||
m_report.next_backoff = backoff_for(m_report.restarts);
|
||||
return m_report;
|
||||
}
|
||||
|
||||
void WorkerSupervisor::stop(std::chrono::milliseconds grace) noexcept
|
||||
{
|
||||
if (m_port.running()) {
|
||||
m_port.terminate(grace);
|
||||
}
|
||||
if (m_report.effects == EffectState::InProgress) {
|
||||
// Termination may interrupt the effect: never report it as done.
|
||||
m_report.effects = EffectState::Unknown;
|
||||
}
|
||||
m_report.state = WorkerState::Stopped;
|
||||
m_report.next_backoff = std::chrono::milliseconds{0};
|
||||
}
|
||||
|
||||
SupervisorReport WorkerSupervisor::report() const
|
||||
{
|
||||
return m_report;
|
||||
}
|
||||
} // namespace ReloadableHost
|
||||
@@ -0,0 +1,220 @@
|
||||
#include "reloadable_host/posix_worker.hpp"
|
||||
#include "reloadable_host/supervisor.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace ReloadableHost;
|
||||
|
||||
/// Deterministic process port: exits are queued by the test.
|
||||
struct FakePort final : WorkerProcessPort {
|
||||
std::vector<std::string> spawns;
|
||||
std::optional<WorkerExit> next_exit;
|
||||
bool alive{false};
|
||||
bool fail_spawn{false};
|
||||
int terminations{0};
|
||||
|
||||
Void::Result::Result<void>
|
||||
spawn(const std::string& command) override
|
||||
{
|
||||
if (fail_spawn) {
|
||||
return std::unexpected{Void::Result::Error{
|
||||
Void::Result::ErrorKind::io, "spawn failed"}};
|
||||
}
|
||||
spawns.push_back(command);
|
||||
alive = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<std::optional<WorkerExit>>
|
||||
try_wait() override
|
||||
{
|
||||
if (!next_exit) {
|
||||
return std::optional<WorkerExit>{};
|
||||
}
|
||||
const WorkerExit exit = *next_exit;
|
||||
next_exit.reset();
|
||||
alive = false;
|
||||
return std::optional<WorkerExit>{exit};
|
||||
}
|
||||
|
||||
void terminate(std::chrono::milliseconds) noexcept override
|
||||
{
|
||||
++terminations;
|
||||
alive = false;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool running() const noexcept override
|
||||
{
|
||||
return alive;
|
||||
}
|
||||
};
|
||||
|
||||
RestartPolicy policy()
|
||||
{
|
||||
return RestartPolicy{.max_restarts = 2,
|
||||
.base_backoff = std::chrono::milliseconds{10},
|
||||
.max_backoff = std::chrono::milliseconds{15}};
|
||||
}
|
||||
|
||||
void crash_restarts_with_bounded_backoff_then_fails()
|
||||
{
|
||||
FakePort port;
|
||||
WorkerSupervisor supervisor{port, "worker", policy()};
|
||||
assert(supervisor.start().has_value());
|
||||
assert(port.spawns.size() == 1);
|
||||
|
||||
port.next_exit = WorkerExit{.exited = true, .code = 1};
|
||||
auto first = supervisor.poll();
|
||||
assert(first.has_value());
|
||||
assert(first->state == WorkerState::Restarting);
|
||||
assert(first->restarts == 1);
|
||||
assert(first->next_backoff == std::chrono::milliseconds{10});
|
||||
|
||||
// The next poll respawns.
|
||||
auto respawned = supervisor.poll();
|
||||
assert(respawned.has_value());
|
||||
assert(respawned->state == WorkerState::Running);
|
||||
assert(port.spawns.size() == 2);
|
||||
|
||||
port.next_exit = WorkerExit{.exited = true, .code = 2};
|
||||
auto second = supervisor.poll();
|
||||
assert(second.has_value());
|
||||
assert(second->restarts == 2);
|
||||
// Exponential backoff saturates at max_backoff.
|
||||
assert(second->next_backoff == std::chrono::milliseconds{15});
|
||||
|
||||
assert(supervisor.poll()->state == WorkerState::Running);
|
||||
port.next_exit = WorkerExit{.exited = true, .signal = 9};
|
||||
auto exhausted = supervisor.poll();
|
||||
assert(exhausted.has_value());
|
||||
assert(exhausted->state == WorkerState::Failed);
|
||||
assert(exhausted->next_backoff == std::chrono::milliseconds{0});
|
||||
assert(exhausted->last_error.find("signal 9") != std::string::npos);
|
||||
}
|
||||
|
||||
void clean_exit_stops_without_restart()
|
||||
{
|
||||
FakePort port;
|
||||
WorkerSupervisor supervisor{port, "worker", policy()};
|
||||
assert(supervisor.start().has_value());
|
||||
port.next_exit = WorkerExit{.exited = true, .code = 0};
|
||||
auto report = supervisor.poll();
|
||||
assert(report.has_value());
|
||||
assert(report->state == WorkerState::Stopped);
|
||||
assert(report->restarts == 0);
|
||||
assert(port.spawns.size() == 1);
|
||||
}
|
||||
|
||||
void crash_with_effect_in_progress_is_unknown()
|
||||
{
|
||||
FakePort port;
|
||||
WorkerSupervisor supervisor{port, "worker", policy()};
|
||||
assert(supervisor.start().has_value());
|
||||
supervisor.begin_effect();
|
||||
assert(supervisor.report().effects == EffectState::InProgress);
|
||||
|
||||
port.next_exit = WorkerExit{.exited = true, .code = 1};
|
||||
(void)supervisor.poll();
|
||||
// Never reported as rolled back or completed.
|
||||
assert(supervisor.report().effects == EffectState::Unknown);
|
||||
|
||||
// A later completion cannot prove the crashed effect finished.
|
||||
supervisor.begin_effect();
|
||||
supervisor.complete_effect();
|
||||
assert(supervisor.report().effects == EffectState::Unknown);
|
||||
}
|
||||
|
||||
void confirmed_effect_completes()
|
||||
{
|
||||
FakePort port;
|
||||
WorkerSupervisor supervisor{port, "worker", policy()};
|
||||
assert(supervisor.start().has_value());
|
||||
supervisor.begin_effect();
|
||||
supervisor.complete_effect();
|
||||
assert(supervisor.report().effects == EffectState::Completed);
|
||||
port.next_exit = WorkerExit{.exited = true, .code = 0};
|
||||
(void)supervisor.poll();
|
||||
assert(supervisor.report().effects == EffectState::Completed);
|
||||
}
|
||||
|
||||
void stop_terminates_once_and_preserves_unknown()
|
||||
{
|
||||
FakePort port;
|
||||
WorkerSupervisor supervisor{port, "worker", policy()};
|
||||
assert(supervisor.start().has_value());
|
||||
supervisor.begin_effect();
|
||||
supervisor.stop();
|
||||
assert(port.terminations == 1);
|
||||
assert(supervisor.report().state == WorkerState::Stopped);
|
||||
// Termination may have interrupted the effect.
|
||||
assert(supervisor.report().effects == EffectState::Unknown);
|
||||
supervisor.stop();
|
||||
assert(port.terminations == 1);
|
||||
}
|
||||
|
||||
void spawn_failure_is_terminal()
|
||||
{
|
||||
FakePort port;
|
||||
port.fail_spawn = true;
|
||||
WorkerSupervisor supervisor{port, "worker", policy()};
|
||||
assert(!supervisor.start().has_value());
|
||||
assert(supervisor.report().state == WorkerState::Failed);
|
||||
assert(supervisor.report().last_error == "spawn failed");
|
||||
}
|
||||
|
||||
/// Poll the supervisor until the worker leaves the running state or the
|
||||
/// bounded wait expires.
|
||||
SupervisorReport wait_for_exit(WorkerSupervisor& supervisor)
|
||||
{
|
||||
for (int i = 0; i < 500; ++i) {
|
||||
(void)supervisor.poll();
|
||||
if (supervisor.report().state != WorkerState::Running) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
}
|
||||
return supervisor.report();
|
||||
}
|
||||
|
||||
void real_posix_port_reports_exit()
|
||||
{
|
||||
{
|
||||
PosixWorkerPort port;
|
||||
WorkerSupervisor supervisor{port, "exit 0", policy()};
|
||||
assert(supervisor.start().has_value());
|
||||
const SupervisorReport report = wait_for_exit(supervisor);
|
||||
assert(report.state == WorkerState::Stopped);
|
||||
}
|
||||
{
|
||||
PosixWorkerPort port;
|
||||
RestartPolicy none;
|
||||
none.max_restarts = 0;
|
||||
WorkerSupervisor supervisor{port, "exit 7", none};
|
||||
assert(supervisor.start().has_value());
|
||||
const SupervisorReport report = wait_for_exit(supervisor);
|
||||
assert(report.state == WorkerState::Failed);
|
||||
assert(report.last_error.find("code 7") != std::string::npos);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
crash_restarts_with_bounded_backoff_then_fails();
|
||||
clean_exit_stops_without_restart();
|
||||
crash_with_effect_in_progress_is_unknown();
|
||||
confirmed_effect_completes();
|
||||
stop_terminates_once_and_preserves_unknown();
|
||||
spawn_failure_is_terminal();
|
||||
real_posix_port_reports_exit();
|
||||
std::puts("reloadable-host supervisor ok");
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user