NetworkedApplications: Discovery-backed service directory with partition policy and optional registration (P-NETWORKED-08)

This commit is contained in:
faumaray committed 2026-12-04 10:42:44 +03:00
1 parent 504f259d02
commit 57ebf3130b
7 files changed
+369 -2

No files matched your search

@@ -341,6 +341,46 @@ namespace
std::filesystem::remove_all(directory);
}
void discovery_registers_the_live_endpoint()
{
// Enabling discovery without an instance identity is rejected.
NetworkedConfig missing_identity;
missing_identity.discovery_enabled = true;
assert(!missing_identity.validate().has_value());
ApplicationResources resources;
resources.ownership = ResourceOwnership::Managed;
NetworkedConfig config;
config.listen_address = "127.0.0.1:0";
config.bearer_token = "secret";
config.discovery_enabled = true;
config.discovery_instance = "test-node";
auto app = NetworkedApplication::create(resources, config);
assert(app.has_value());
assert(app->directory() != nullptr);
assert(app->start().has_value());
const auto port = app->health().bound_port;
assert(app->health().discovery_registered);
assert(app->health().discovery_error.empty());
auto records = app->directory()->resolve("networked-kv");
assert(records.has_value());
assert(records->size() == 1);
assert((*records)[0].instance == "test-node");
assert((*records)[0].endpoint.port == port);
assert(app->stop().has_value());
assert(!app->directory()->registered());
auto after = app->directory()->resolve("networked-kv");
assert(after.has_value());
assert(after->empty());
// The directory is optional and absent by default.
auto plain = NetworkedApplication::create(resources, NetworkedConfig{});
assert(plain.has_value());
assert(plain->directory() == nullptr);
}
} // namespace
int main()
@@ -354,6 +394,7 @@ int main()
durable_profile_survives_restart();
config_reload_publishes_a_new_generation();
durable_backup_and_restore_roundtrip();
discovery_registers_the_live_endpoint();
std::puts("networked-kv lifecycle ok");
return 0;
}