1 parent
3851aeb703
commit
053ee5b296
23 files changed
+845
-93
No files matched your search
@@ -80,6 +80,16 @@ if(_all_generated)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# A few fixtures construct archives and signatures through the upstream C
|
||||
# APIs directly. Those are test implementation dependencies, not part of
|
||||
# the public interface of Void's shared modules.
|
||||
if(TARGET LibArchive::LibArchive)
|
||||
target_link_libraries(VoidTests PRIVATE LibArchive::LibArchive)
|
||||
endif()
|
||||
if(TARGET OpenSSL::Crypto)
|
||||
target_link_libraries(VoidTests PRIVATE OpenSSL::Crypto)
|
||||
endif()
|
||||
|
||||
add_test(NAME VoidTests COMMAND VoidTests)
|
||||
|
||||
add_test(NAME VoidInstalledComponentConsumers
|
||||
|
||||
@@ -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
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
project(VoidExternalConsumer LANGUAGES CXX)
|
||||
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS
|
||||
Net
|
||||
Security
|
||||
Sqlite
|
||||
Stacktrace
|
||||
)
|
||||
|
||||
add_executable(void_external_consumer main.cpp)
|
||||
target_link_libraries(void_external_consumer PRIVATE
|
||||
Void::Net
|
||||
Void::Security
|
||||
Void::Sqlite
|
||||
Void::Stacktrace
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME VoidExternalConsumer COMMAND void_external_consumer)
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
#include <Void/Net/Url.hpp>
|
||||
#include <Void/Security/Security.hpp>
|
||||
#include <Void/Sqlite/Sqlite.hpp>
|
||||
#include <Void/Stacktrace/Stacktrace.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto url = Void::Net::Url::parse("https://example.invalid/path");
|
||||
const auto token = Void::Security::hash_token("void-consumer-token");
|
||||
auto database = Void::Sqlite::Database::open(":memory:");
|
||||
const auto frames = Void::Stacktrace::capture_stacktrace(0, 1);
|
||||
|
||||
return url && url->target == "/path" && token && !token->empty() &&
|
||||
database && frames.size() <= 1
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
@@ -54,3 +54,8 @@ run_consumer(Audited
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE)
|
||||
|
||||
# Compiled shared modules keep their third-party implementation dependencies
|
||||
# private, but every installed runtime library must remain linkable and
|
||||
# executable from a clean consumer project.
|
||||
run_consumer(External)
|
||||
@@ -38,7 +38,7 @@ Void::Testing::Test field_scope_nests()
|
||||
|
||||
FieldScope a{"a", "1"};
|
||||
{
|
||||
FieldScope b{{{"b", "2"}, {"c", "3"}}};
|
||||
FieldScope b{{"b", "2"}, {"c", "3"}};
|
||||
log.info("two scopes");
|
||||
}
|
||||
log.info("one scope");
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <Void/ShortUrl/ShortUrl.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
class Shortener final : public Void::ShortUrl::IShortener
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]] std::string_view provider_id() const noexcept override
|
||||
{
|
||||
return "test";
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::ShortUrl::Health health() const override
|
||||
{
|
||||
return {.status = Void::ShortUrl::HealthStatus::healthy};
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::ShortUrl::ShortenResult
|
||||
shorten(const Void::ShortUrl::ShortenRequest& request) override
|
||||
{
|
||||
return {
|
||||
.short_url = "https://sho.rt/s/Ab3dE5fG7h",
|
||||
.key = "Ab3dE5fG7h",
|
||||
.expires_at_unix_seconds = request.expires_at_unix_seconds,
|
||||
};
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Void::Testing::Test short_url_service_contract()
|
||||
{
|
||||
Shortener shortener;
|
||||
Void::Testing::expect_eq(shortener.service_name(),
|
||||
Void::ShortUrl::kServiceId);
|
||||
Void::Testing::expect_eq(shortener.service_version(), std::uint32_t{1});
|
||||
Void::Testing::expect_eq(shortener.provider_id(), std::string_view{"test"});
|
||||
Void::Testing::expect_eq(shortener.health().status,
|
||||
Void::ShortUrl::HealthStatus::healthy);
|
||||
|
||||
auto result = shortener.shorten({.target_url = "https://example.com/a"});
|
||||
Void::Testing::expect(result.ok());
|
||||
Void::Testing::expect_eq(result.key, std::string{"Ab3dE5fG7h"});
|
||||
}
|
||||
|
||||
Void::Testing::Test short_url_resolution_is_optional()
|
||||
{
|
||||
Shortener shortener;
|
||||
auto result = shortener.resolve({.key = "Ab3dE5fG7h"});
|
||||
Void::Testing::expect(!result.ok());
|
||||
Void::Testing::expect_eq(result.error.code,
|
||||
Void::ShortUrl::ErrorCode::unsupported);
|
||||
}
|
||||
Reference in new issue
Block a user