update
CI / GCC 16 / C++26 / sanitizers (push) Failing after 4s
CI / GCC 16 / C++26 / werror (push) Failing after 3s
CI / GCC 16 / C++26 / default (push) Failing after 1m48s

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-25 23:42:52 +03:00
1 parent 3851aeb703
commit 053ee5b296
23 files changed
+845 -93

No files matched your search

+88
View File
@@ -10,7 +10,10 @@
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <filesystem>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
@@ -147,4 +150,89 @@ Void::Testing::Test internal_service_reload_migrates_and_swaps()
Void::Testing::expect_eq(v2->accumulate(0), 40); // state migrated
}
// A validator rejection during the automatic reload callback must preserve
// the last accepted service instead of publishing the rejected candidate.
Void::Testing::Test plugin_service_reload_validation_preserves_last_good()
{
Void::FileSystem::TempDir tmp{"void_svcplugin_validate"};
const auto so = tmp.path() / "calc.so";
std::filesystem::copy_file(VOID_SERVICE_V1_PATH, so);
Void::Service::ServiceRegistry registry;
Void::Plugin::PluginManager plugins;
Void::Testing::expect(plugins.load(so).has_value());
Void::Service::PluginServiceBinding<VoidTest::ICalc> binding{
plugins, registry, "CalcPlugin",
[](const std::shared_ptr<VoidTest::ICalc>& service) {
return service->version() == 1;
}};
Void::Testing::expect(binding.bind());
binding.enable_hot_reload();
install(VOID_SERVICE_V2_PATH, so);
Void::Testing::expect(plugins.reload("CalcPlugin").has_value());
auto service = registry.get<VoidTest::ICalc>();
Void::Testing::expect(service != nullptr);
Void::Testing::expect_eq(service->version(), 1);
}
// PluginManager intentionally invokes a copied callback list outside its
// mutex. Destroying a binding after that copy must make its callback inert.
Void::Testing::Test plugin_service_callback_is_safe_after_binding_destruction()
{
Void::FileSystem::TempDir tmp{"void_svcplugin_lifetime"};
const auto so = tmp.path() / "calc.so";
std::filesystem::copy_file(VOID_SERVICE_V1_PATH, so);
Void::Service::ServiceRegistry registry;
Void::Plugin::PluginManager plugins;
Void::Testing::expect(plugins.load(so).has_value());
std::mutex gateMutex;
std::condition_variable gateChanged;
bool callbackEntered = false;
bool releaseCallback = false;
const auto blocker = plugins.on_reloaded([&](std::string_view) {
std::unique_lock lock{gateMutex};
callbackEntered = true;
gateChanged.notify_all();
gateChanged.wait(lock, [&] { return releaseCallback; });
});
auto binding =
std::make_unique<Void::Service::PluginServiceBinding<VoidTest::ICalc>>(
plugins, registry, "CalcPlugin");
Void::Testing::expect(binding->bind());
binding->enable_hot_reload();
install(VOID_SERVICE_V2_PATH, so);
std::atomic<bool> reloadSucceeded{false};
std::thread reloader{[&] {
reloadSucceeded.store(plugins.reload("CalcPlugin").has_value(),
std::memory_order_release);
}};
bool callbackWasObserved = false;
{
std::unique_lock lock{gateMutex};
callbackWasObserved = gateChanged.wait_for(
lock, std::chrono::seconds{5}, [&] { return callbackEntered; });
}
binding.reset();
{
std::lock_guard lock{gateMutex};
releaseCallback = true;
}
gateChanged.notify_all();
reloader.join();
plugins.remove_on_reloaded(blocker);
Void::Testing::expect(callbackWasObserved);
Void::Testing::expect(reloadSucceeded.load(std::memory_order_acquire));
auto service = registry.get<VoidTest::ICalc>();
Void::Testing::expect(service != nullptr);
Void::Testing::expect_eq(service->version(), 1);
}
#endif // service plugins available