Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
077c046
add single, fixed generation dimension
snps-fricke Nov 4, 2026
acd5219
assign joiners to generations
snps-fricke Nov 6, 2026
dfb51ce
support duplicate participant names
snps-fricke Nov 9, 2026
13e2ffa
stamp generation in supplemental descriptor data
snps-fricke Nov 9, 2026
1c5a5bf
track system state and tag used generations
snps-fricke Nov 10, 2026
6541e78
add session placement abstraction
snps-fricke Nov 13, 2026
0499748
limit generation support to "session/" prefix
snps-fricke Nov 13, 2026
62e04f1
pin workflow configuration per session
snps-fricke Nov 16, 2026
d3d3a4d
autonomous participant admission
snps-fricke Nov 16, 2026
9f06913
prevent controllers from re-joining before start
snps-fricke Nov 16, 2026
68e5be4
reverse admission order to prioritize restarts
snps-fricke Nov 16, 2026
8b577e3
add registry event lister prototype
snps-fricke Nov 17, 2026
089ae22
registry: emit generation creation event
snps-fricke Nov 17, 2026
5d22496
registry: emit generation state events
snps-fricke Nov 18, 2026
ee6e618
registry-listener: dump NDJSON
snps-fricke Nov 18, 2026
3401a6e
add generation identity to participant events
snps-fricke Nov 18, 2026
8227df5
isolate generated domain sockets across instances
snps-fricke Nov 20, 2026
4081680
add `registry-sessions` capability and validate it
snps-fricke Nov 25, 2026
2cbb589
warn when joining a session with fixed local URIs
snps-fricke Nov 25, 2026
a222ebe
restrict session admission to newest generation
snps-fricke Nov 26, 2026
16d12f2
let controllers rejoin before worklow configured
snps-fricke Nov 27, 2026
f4c9ca3
add missing license headers
snps-fricke Nov 27, 2026
7f7f5b5
fix outdated test
snps-fricke Nov 30, 2026
55faf25
fix msvc narrowing warning
snps-fricke Nov 30, 2026
5bd49c0
fix domain socket validity checks on windows
snps-fricke Nov 30, 2026
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
294 changes: 294 additions & 0 deletions SilKit/IntegrationTests/ITest_DomainSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@
// Participants on the same host connect via local domain sockets by default, and via TCP if domain sockets are
// disabled.

#include <algorithm>
#include <chrono>
#include <condition_variable>
#include <cstdint>
#include <future>
#include <memory>
#include <mutex>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#include "silkit/SilKit.hpp"
#include "silkit/experimental/participant/ParticipantExtensions.hpp"
#include "silkit/vendor/CreateSilKitRegistry.hpp"

#include "IntegrationTestUtils.hpp"
Expand All @@ -19,6 +31,7 @@ namespace {

using IntegrationTestUtils::MakeUniqueLogName;
using IntegrationTestUtils::ScopedLogFiles;
using namespace std::chrono_literals;

auto MakeConfig(const std::string& logName, const std::string& middleware) -> std::string
{
Expand All @@ -27,6 +40,7 @@ auto MakeConfig(const std::string& logName, const std::string& middleware) -> st
FlushLevel: Trace
Sinks:
- Type: File
Format: Simple
Level: Debug
LogName: )" + logName + "\n" + middleware;
}
Expand Down Expand Up @@ -72,4 +86,284 @@ TEST(ITest_DomainSockets, participants_connect_via_tcp_if_domain_sockets_are_dis
EXPECT_THAT(log, testing::Not(testing::HasSubstr("New connection from [local=local://")));
}

auto JoinWithAcceptorUris(bool session, bool enableDomainSockets, bool fixedTcpPort) -> std::string
{
ScopedLogFiles logs{MakeUniqueLogName("FixedAcceptors")};
auto registry =
SilKit::Vendor::Vector::CreateSilKitRegistry(SilKit::Config::ParticipantConfigurationFromString(""));
const auto registryUri = registry->StartListening("silkit://127.0.0.1:0");
const auto localUri = "local://" + logs.Prefix() + ".sock";
auto middleware = std::string{"\nMiddleware:\n EnableDomainSockets: "} + (enableDomainSockets ? "true" : "false")
+ "\n AcceptorUris:\n - tcp://127.0.0.1:0\n - " + localUri + "\n";
if (fixedTcpPort)
{
// Use the registry's port to exercise a known bind collision without reserving a hard-coded port.
middleware += " - tcp://127.0.0.1" + registryUri.substr(registryUri.rfind(':')) + "\n";
}
const auto config = SilKit::Config::ParticipantConfigurationFromString(MakeConfig(logs.Prefix(), middleware));
{
auto participant =
SilKit::CreateParticipant(config, "TestParticipant", registryUri + (session ? "/session/fixed" : "/fixed"));
}
return logs.ReadAll();
}

TEST(ITest_DomainSockets, registry_session_warns_once_about_fixed_acceptors_before_binding)
{
const auto log = JoinWithAcceptorUris(true, true, true);
const auto warning = log.find("with fixed acceptor endpoints: ");
ASSERT_NE(warning, std::string::npos) << log;
const auto warningText = log.substr(warning, log.find('\n', warning) - warning);
EXPECT_THAT(warningText, testing::HasSubstr("local://FixedAcceptors"));
EXPECT_THAT(warningText, testing::HasSubstr("tcp://127.0.0.1:"));
EXPECT_THAT(warningText, testing::Not(testing::HasSubstr("tcp://127.0.0.1:0")));
EXPECT_EQ(log.find("with fixed acceptor endpoints: ", warning + 1), std::string::npos);
const auto bindError = log.find("Unable to accept TCP connections on");
ASSERT_NE(bindError, std::string::npos) << log;
EXPECT_LT(warning, bindError);
}

TEST(ITest_DomainSockets, registry_session_does_not_warn_for_dynamic_tcp_or_disabled_domain_sockets)
{
EXPECT_THAT(JoinWithAcceptorUris(true, false, false),
testing::Not(testing::HasSubstr("with fixed acceptor endpoints: ")));
}

TEST(ITest_DomainSockets, non_session_does_not_warn_about_fixed_acceptors)
{
EXPECT_THAT(JoinWithAcceptorUris(false, true, true),
testing::Not(testing::HasSubstr("with fixed acceptor endpoints: ")));
}

struct ReceivedData
{
void Add(const SilKit::Services::PubSub::DataMessageEvent& event)
{
std::lock_guard<std::mutex> lock{mutex};
messages.emplace_back(event.data.begin(), event.data.end());
changed.notify_all();
}

auto WaitFor(uint8_t value) -> bool
{
std::unique_lock<std::mutex> lock{mutex};
return changed.wait_for(lock, 5s, [&] {
return std::find(messages.begin(), messages.end(), std::vector<uint8_t>{value}) != messages.end();
});
}

std::mutex mutex;
std::condition_variable changed;
std::vector<std::vector<uint8_t>> messages;
};

struct SocketGeneration
{
SocketGeneration(const std::shared_ptr<SilKit::Config::IParticipantConfiguration>& config,
const std::string& registryUri, ReceivedData& received)
{
publisherParticipant = SilKit::CreateParticipant(config, "Publisher", registryUri);
publisher = publisherParticipant->CreateDataPublisher("Publisher", spec, 1);
publisherLifecycle =
publisherParticipant->CreateLifecycleService({SilKit::Services::Orchestration::OperationMode::Coordinated});

subscriberParticipant = SilKit::CreateParticipant(config, "Subscriber", registryUri);
subscriberParticipant->CreateDataSubscriber("Subscriber", spec,
[&received](auto*, const auto& event) { received.Add(event); });
subscriberLifecycle = subscriberParticipant->CreateLifecycleService(
{SilKit::Services::Orchestration::OperationMode::Coordinated});

controllerParticipant = SilKit::CreateParticipant(config, "Controller", registryUri);
controllerParticipant->CreateSystemMonitor()->AddParticipantStatusHandler([this](const auto& status) {
if (status.state == SilKit::Services::Orchestration::ParticipantState::Running)
{
if (status.participantName == "Publisher")
{
publisherRunning.set_value();
}
else if (status.participantName == "Subscriber")
{
subscriberRunning.set_value();
}
}
});
SilKit::Experimental::Participant::CreateSystemController(controllerParticipant.get())
->SetWorkflowConfiguration({{"Publisher", "Subscriber"}});
}

void Start()
{
auto publisherReady = publisherRunning.get_future();
auto subscriberReady = subscriberRunning.get_future();
publisherDone = publisherLifecycle->StartLifecycle();
subscriberDone = subscriberLifecycle->StartLifecycle();
ASSERT_EQ(publisherReady.wait_for(5s), std::future_status::ready);
ASSERT_EQ(subscriberReady.wait_for(5s), std::future_status::ready);
}

void Stop()
{
publisherLifecycle->Stop("Socket isolation test");
ASSERT_EQ(publisherDone.wait_for(5s), std::future_status::ready);
ASSERT_EQ(subscriberDone.wait_for(5s), std::future_status::ready);
EXPECT_EQ(publisherDone.get(), SilKit::Services::Orchestration::ParticipantState::Shutdown);
EXPECT_EQ(subscriberDone.get(), SilKit::Services::Orchestration::ParticipantState::Shutdown);
}

void Publish(uint8_t value)
{
const std::vector<uint8_t> data{value};
publisher->Publish(SilKit::Util::ToSpan(data));
}

SilKit::Services::PubSub::PubSubSpec spec{"SocketIsolation", "application/octet-stream"};
std::promise<void> publisherRunning;
std::promise<void> subscriberRunning;
std::future<SilKit::Services::Orchestration::ParticipantState> publisherDone;
std::future<SilKit::Services::Orchestration::ParticipantState> subscriberDone;
SilKit::Services::PubSub::IDataPublisher* publisher{nullptr};
SilKit::Services::Orchestration::ILifecycleService* publisherLifecycle{nullptr};
SilKit::Services::Orchestration::ILifecycleService* subscriberLifecycle{nullptr};
std::unique_ptr<SilKit::IParticipant> publisherParticipant;
std::unique_ptr<SilKit::IParticipant> subscriberParticipant;
std::unique_ptr<SilKit::IParticipant> controllerParticipant;
};

auto ParticipantSocketPaths(const std::string& log) -> std::set<std::string>
{
std::set<std::string> paths;
std::istringstream lines{log};
std::string line;
const std::regex localPath{R"(UriPath: (.*\.silkit))"};
while (std::getline(lines, line))
{
if (line.find("Found local domain acceptor endpoint URI") == std::string::npos)
{
continue;
}
std::smatch match;
const auto matched = std::regex_search(line, match, localPath);
EXPECT_TRUE(matched) << line;
if (matched)
{
paths.insert(match[1].str());
}
}
return paths;
}

void CheckGenerationIsolation(bool removeOldest)
{
ScopedLogFiles firstLogs{MakeUniqueLogName("ITest_DomainSockets_First")};
ScopedLogFiles secondLogs{MakeUniqueLogName("ITest_DomainSockets_Second")};
ScopedLogFiles replacementLogs{MakeUniqueLogName("ITest_DomainSockets_Replacement")};
ScopedLogFiles lateLogs{MakeUniqueLogName("ITest_DomainSockets_Late")};
const auto configFor = [](const ScopedLogFiles& logs) {
return SilKit::Config::ParticipantConfigurationFromString(MakeConfig(logs.Prefix(), ""));
};
auto registry =
SilKit::Vendor::Vector::CreateSilKitRegistry(SilKit::Config::ParticipantConfigurationFromString(""));
const auto registryUri = registry->StartListening("silkit://127.0.0.1:0") + "/session/socket-isolation";
ReceivedData firstReceived;
ReceivedData secondReceived;
ReceivedData replacementReceived;
ReceivedData lateReceived;

auto first = std::make_unique<SocketGeneration>(configFor(firstLogs), registryUri, firstReceived);
ASSERT_NO_FATAL_FAILURE(first->Start());

auto second = std::make_unique<SocketGeneration>(configFor(secondLogs), registryUri, secondReceived);
ASSERT_NO_FATAL_FAILURE(second->Start());

const auto firstPaths = ParticipantSocketPaths(firstLogs.ReadAll());
const auto secondPaths = ParticipantSocketPaths(secondLogs.ReadAll());
ASSERT_FALSE(firstPaths.empty());
ASSERT_FALSE(secondPaths.empty());
for (const auto& path : firstPaths)
{
EXPECT_EQ(secondPaths.count(path), 0u);
}

auto& removed = removeOldest ? first : second;
auto& survivor = removeOldest ? second : first;
auto& removedReceived = removeOldest ? firstReceived : secondReceived;
auto& survivorReceived = removeOldest ? secondReceived : firstReceived;

removed->Publish(1);
survivor->Publish(2);
ASSERT_TRUE(removedReceived.WaitFor(1));
ASSERT_TRUE(survivorReceived.WaitFor(2));

ASSERT_NO_FATAL_FAILURE(removed->Stop());
removed.reset();
EXPECT_EQ(survivor->publisherLifecycle->State(), SilKit::Services::Orchestration::ParticipantState::Running);
EXPECT_EQ(survivor->subscriberLifecycle->State(), SilKit::Services::Orchestration::ParticipantState::Running);
survivor->Publish(3);
ASSERT_TRUE(survivorReceived.WaitFor(3));

const auto secondLogSize = removeOldest ? secondLogs.ReadAll().size() : 0u;
auto late = SilKit::CreateParticipant(configFor(lateLogs), "LateSubscriber", registryUri);
if (removeOldest)
{
const auto log = secondLogs.ReadAll();
EXPECT_TRUE(std::any_of(secondPaths.begin(), secondPaths.end(), [&](const auto& path) {
return log.find("New connection from [local=local://" + path + ", remote=", secondLogSize)
!= std::string::npos;
})) << log;
}
late->CreateDataSubscriber("LateSubscriber", survivor->spec,
[&lateReceived](auto*, const auto& event) { lateReceived.Add(event); });

auto replacement = std::make_unique<SocketGeneration>(configFor(replacementLogs), registryUri, replacementReceived);
ASSERT_NO_FATAL_FAILURE(replacement->Start());
replacement->Publish(4);
ASSERT_TRUE(replacementReceived.WaitFor(4));
// If the newest generation was removed, the late subscriber opens its replacement instead of joining the survivor.
ASSERT_TRUE(lateReceived.WaitFor(removeOldest ? 3 : 4));

survivor->Publish(5);
ASSERT_TRUE(survivorReceived.WaitFor(5));
if (removeOldest)
{
ASSERT_TRUE(lateReceived.WaitFor(5));
}

ASSERT_NO_FATAL_FAILURE(replacement->Stop());
replacement.reset();
ASSERT_NO_FATAL_FAILURE(survivor->Stop());
survivor.reset();
late.reset();

using testing::ElementsAre;
EXPECT_THAT(removedReceived.messages, ElementsAre(ElementsAre(uint8_t{1})));
EXPECT_THAT(survivorReceived.messages,
ElementsAre(ElementsAre(uint8_t{2}), ElementsAre(uint8_t{3}), ElementsAre(uint8_t{5})));
EXPECT_THAT(replacementReceived.messages, ElementsAre(ElementsAre(uint8_t{4})));
if (removeOldest)
{
EXPECT_THAT(lateReceived.messages, ElementsAre(ElementsAre(uint8_t{3}), ElementsAre(uint8_t{5})));
}
else
{
EXPECT_THAT(lateReceived.messages, ElementsAre(ElementsAre(uint8_t{4})));
}

for (const auto* logs : {&firstLogs, &secondLogs, &replacementLogs, &lateLogs})
{
EXPECT_THAT(logs->ReadAll(), testing::Not(testing::HasSubstr("New connection from [local=tcp://")));
}
EXPECT_THAT(firstLogs.ReadAll(), testing::HasSubstr("New connection from [local=local://"));
EXPECT_THAT(secondLogs.ReadAll(), testing::HasSubstr("New connection from [local=local://"));
}

TEST(ITest_DomainSockets, generations_remain_isolated_when_the_older_generation_is_removed)
{
CheckGenerationIsolation(true);
}

TEST(ITest_DomainSockets, generations_remain_isolated_when_the_newer_generation_is_removed)
{
CheckGenerationIsolation(false);
}

} // namespace
13 changes: 7 additions & 6 deletions SilKit/IntegrationTests/ITest_SystemMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ TEST_F(ITest_SystemMonitor, discover_services)
SilKit::Services::Orchestration::ISystemMonitor* secondSystemMonitor = nullptr;
SilKit::Services::Orchestration::ISystemMonitor* thirdSystemMonitor = nullptr;

testing::Sequence sequence, secondSequence, thirdSequence;
testing::Sequence sequence, secondSequence;

std::promise<void> thirdParticipantDisconnectedPromiseA, thirdParticipantDisconnectedPromiseB;
auto thirdParticipantDisconnectedFutureA = thirdParticipantDisconnectedPromiseA.get_future();
Expand All @@ -122,9 +122,9 @@ TEST_F(ITest_SystemMonitor, discover_services)
.InSequence(secondSequence);
}

EXPECT_CALL(sequencePoints, A_BeforeCreateThirdParticipant())
.Times(1)
.InSequence(sequence, secondSequence, thirdSequence);
testing::Expectation beforeCreateThird = EXPECT_CALL(sequencePoints, A_BeforeCreateThirdParticipant())
.Times(1)
.InSequence(sequence, secondSequence);
{
EXPECT_CALL(callbacks, ParticipantConnectedHandler(IsParticipant(thirdParticipantConnection)))
.Times(1)
Expand All @@ -134,12 +134,13 @@ TEST_F(ITest_SystemMonitor, discover_services)
.InSequence(secondSequence);
}
{
// The order in which the already connected participants are reported to the new participant is unspecified.
EXPECT_CALL(thirdCallbacks, ParticipantConnectedHandler(IsParticipant(firstParticipantConnection)))
.Times(1)
.InSequence(thirdSequence);
.After(beforeCreateThird);
EXPECT_CALL(thirdCallbacks, ParticipantConnectedHandler(IsParticipant(secondParticipantConnection)))
.Times(1)
.InSequence(thirdSequence);
.After(beforeCreateThird);
}
EXPECT_CALL(sequencePoints, B_AfterCreateThirdParticipant()).Times(1).InSequence(sequence, secondSequence);
{
Expand Down
3 changes: 2 additions & 1 deletion SilKit/source/core/internal/ServiceConfigKeys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Core {
namespace Discovery {

const std::string simulationName = "participant.simulationName";
const std::string generation = "participant.generation";

// controller-specific keys
const std::string controllerType = "controller.type";
Expand Down Expand Up @@ -79,4 +80,4 @@ const std::string timeSyncDynamicStepSize = "TimeSyncDynamicStepSize";

} // namespace Discovery
} // namespace Core
} // namespace SilKit
} // namespace SilKit
Loading
Loading