From 3c752937a468799cef77209738bbc063f59f3b33 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 14:16:33 +0000 Subject: [PATCH] test: use unique ipc addresses that the tests remove - the in-process tests used fixed, relative ipc addresses; the socket files stayed in the build directory (99 files after 6 runs), and two runs of the same test at the same time could share a socket - use test::IpcAddress: a unique path in /tmp that the destructor removes - drop the session suffix of the inproc addresses: an inproc address is local to the process Co-Authored-By: Claude Opus 5.5 --- test/channel/_channel.cxx | 3 +- test/device/_multiple_devices.cxx | 7 ++-- test/message/_message.cxx | 47 +++++++++++++------------ test/protocols/_push_pull_multipart.cxx | 26 ++++++++------ test/region/_region.cxx | 39 ++++++++++---------- test/transport/_transfer_timeout.cxx | 8 ++--- 6 files changed, 70 insertions(+), 60 deletions(-) diff --git a/test/channel/_channel.cxx b/test/channel/_channel.cxx index 9ee10957..fbfcad4c 100644 --- a/test/channel/_channel.cxx +++ b/test/channel/_channel.cxx @@ -99,7 +99,8 @@ TEST(Channel, Validation) auto testConnectedPeers(std::string const& transport) { ProgOptions config; - string const address(tools::ToString("ipc://", test::Configure(config))); + test::Configure(config); + test::IpcAddress const address("connected_peers"); unsigned long constexpr zero(0), one(1); auto factory(TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config)); diff --git a/test/device/_multiple_devices.cxx b/test/device/_multiple_devices.cxx index 45247801..3c00b17d 100644 --- a/test/device/_multiple_devices.cxx +++ b/test/device/_multiple_devices.cxx @@ -10,6 +10,7 @@ #include "TestReceiver.h" #include "../helper/ControlDevice.h" +#include "../helper/Transport.h" #include @@ -36,12 +37,14 @@ void control(Device& device) class MultipleDevices : public ::testing::Test { public: + test::IpcAddress const fAddress{"multiple_devices"}; + bool TestFirst() { test::Sender sender("data"); sender.SetTransport("zeromq"); - Channel channel("push", "connect", "ipc://multiple-devices-test"); + Channel channel("push", "connect", fAddress); channel.UpdateRateLogging(0); sender.AddChannel("data", std::move(channel)); @@ -54,7 +57,7 @@ class MultipleDevices : public ::testing::Test { test::Receiver receiver("data"); receiver.SetTransport("zeromq"); - Channel channel("pull", "bind", "ipc://multiple-devices-test"); + Channel channel("pull", "bind", fAddress); channel.UpdateRateLogging(0); receiver.AddChannel("data", std::move(channel)); diff --git a/test/message/_message.cxx b/test/message/_message.cxx index 43992344..e4ec3699 100644 --- a/test/message/_message.cxx +++ b/test/message/_message.cxx @@ -43,7 +43,7 @@ auto AsStringView(Message const& msg) -> string_view return {static_cast(msg.GetData()), msg.GetSize()}; } -auto RunPushPullWithMsgResize(string const & transport, string const & _address, bool expandedShmMetadata = false) -> void +auto RunPushPullWithMsgResize(string const & transport, string const & name, bool expandedShmMetadata = false) -> void { ProgOptions config; test::Configure(config, tools::Uuid(), expandedShmMetadata); @@ -51,7 +51,7 @@ auto RunPushPullWithMsgResize(string const & transport, string const & _address, Channel push{"Push", "push", factory}; Channel pull{"Pull", "pull", factory}; - auto const address(tools::ToString(_address, "_", transport, "_", config.GetProperty("session"))); + test::IpcAddress const address(tools::ToString(name, "_", transport)); ASSERT_TRUE(push.Bind(address)); ASSERT_TRUE(pull.Connect(address)); @@ -136,7 +136,7 @@ auto CheckMsgAlignment(Message const& msg, fair::mq::Alignment alignment) -> boo return (reinterpret_cast(msg.GetData()) % static_cast(alignment)) == 0; // NOLINT } -auto RunPushPullWithAlignment(string const& transport, string const& _address, bool expandedShmMetadata = false) -> void +auto RunPushPullWithAlignment(string const& transport, string const& name, bool expandedShmMetadata = false) -> void { ProgOptions config; test::Configure(config, tools::Uuid(), expandedShmMetadata); @@ -144,7 +144,7 @@ auto RunPushPullWithAlignment(string const& transport, string const& _address, b Channel push{"Push", "push", factory}; Channel pull{"Pull", "pull", factory}; - auto const address(tools::ToString(_address, "_", transport, "_", config.GetProperty("session"))); + test::IpcAddress const address(tools::ToString(name, "_", transport)); ASSERT_TRUE(push.Bind(address)); ASSERT_TRUE(pull.Connect(address)); @@ -189,7 +189,7 @@ auto RunPushPullWithAlignment(string const& transport, string const& _address, b ASSERT_TRUE(CheckMsgAlignment(*msgCopy, align32)); } -auto EmptyMessage(string const& transport, string const& _address, bool expandedShmMetadata = false) -> void +auto EmptyMessage(string const& transport, string const& name, bool expandedShmMetadata = false) -> void { ProgOptions config; test::Configure(config, tools::Uuid(), expandedShmMetadata); @@ -197,7 +197,7 @@ auto EmptyMessage(string const& transport, string const& _address, bool expanded Channel push{"Push", "push", factory}; Channel pull{"Pull", "pull", factory}; - auto const address(tools::ToString(_address, "_", transport, "_", config.GetProperty("session"))); + test::IpcAddress const address(tools::ToString(name, "_", transport)); ASSERT_TRUE(push.Bind(address)); ASSERT_TRUE(pull.Connect(address)); @@ -268,7 +268,7 @@ auto ZeroCopy(bool expandedShmMetadata = false) -> void // The "zero copy" property of the Copy() method is an implementation detail and is not guaranteed. // Currently it holds true for the shmem (across devices) and for zeromq (within same device) transports. -auto ZeroCopyFromUnmanaged(string const& address, bool expandedShmMetadata, uint64_t rcSegmentSize) -> void +auto ZeroCopyFromUnmanaged(string const& name, bool expandedShmMetadata, uint64_t rcSegmentSize) -> void { ProgOptions config1; ProgOptions config2; @@ -293,8 +293,9 @@ auto ZeroCopyFromUnmanaged(string const& address, bool expandedShmMetadata, uint Channel push("Push", "push", factory1); Channel pull("Pull", "pull", factory2); - ASSERT_TRUE(push.Bind(address + "_" + session)); - ASSERT_TRUE(pull.Connect(address + "_" + session)); + test::IpcAddress const address(name); + ASSERT_TRUE(push.Bind(address)); + ASSERT_TRUE(pull.Connect(address)); const size_t offset = 100; auto msg1(push.NewMessage(region, static_cast(region->GetData()), msgSize, nullptr)); @@ -363,17 +364,17 @@ auto ZeroCopyFromUnmanaged(string const& address, bool expandedShmMetadata, uint TEST(Resize, zeromq) // NOLINT { - RunPushPullWithMsgResize("zeromq", "ipc://test_message_resize"); + RunPushPullWithMsgResize("zeromq", "message_resize"); } TEST(Resize, shmem) // NOLINT { - RunPushPullWithMsgResize("shmem", "ipc://test_message_resize"); + RunPushPullWithMsgResize("shmem", "message_resize"); } TEST(Resize, shmem_expanded_metadata) // NOLINT { - RunPushPullWithMsgResize("shmem", "ipc://test_message_resize", true); + RunPushPullWithMsgResize("shmem", "message_resize", true); } TEST(Rebuild, zeromq) // NOLINT @@ -393,32 +394,32 @@ TEST(Rebuild, shmem_expanded_metadata) // NOLINT TEST(Alignment, shmem) // NOLINT { - RunPushPullWithAlignment("shmem", "ipc://test_message_alignment"); + RunPushPullWithAlignment("shmem", "message_alignment"); } TEST(Alignment, shmem_expanded_metadata) // NOLINT { - RunPushPullWithAlignment("shmem", "ipc://test_message_alignment", true); + RunPushPullWithAlignment("shmem", "message_alignment", true); } TEST(Alignment, zeromq) // NOLINT { - RunPushPullWithAlignment("zeromq", "ipc://test_message_alignment"); + RunPushPullWithAlignment("zeromq", "message_alignment"); } TEST(EmptyMessage, zeromq) // NOLINT { - EmptyMessage("zeromq", "ipc://test_empty_message"); + EmptyMessage("zeromq", "empty_message"); } TEST(EmptyMessage, shmem) // NOLINT { - EmptyMessage("shmem", "ipc://test_empty_message"); + EmptyMessage("shmem", "empty_message"); } TEST(EmptyMessage, shmem_expanded_metadata) // NOLINT { - EmptyMessage("shmem", "ipc://test_empty_message", true); + EmptyMessage("shmem", "empty_message", true); } // GetMeta() + GetDataAddressFromHandle() round-trip: simulates a consumer device that @@ -520,7 +521,7 @@ auto ReuseReceivedRegionMessage() -> void Channel push{"Push", "push", factory}; Channel pull{"Pull", "pull", factory}; - auto const address(tools::ToString("ipc://test_reuse_received_region_msg_", config.GetProperty("session"))); + test::IpcAddress const address("reuse_received_region_msg"); ASSERT_TRUE(push.Bind(address)); ASSERT_TRUE(pull.Connect(address)); @@ -632,22 +633,22 @@ TEST(SideChannel, errors) // NOLINT TEST(ZeroCopyFromUnmanaged, shmem) // NOLINT { - ZeroCopyFromUnmanaged("ipc://test_zerocopy_unmanaged", false, 10000000); + ZeroCopyFromUnmanaged("zerocopy_unmanaged", false, 10000000); } TEST(ZeroCopyFromUnmanaged, shmem_expanded_metadata) // NOLINT { - ZeroCopyFromUnmanaged("ipc://test_zerocopy_unmanaged_expanded", true, 10000000); + ZeroCopyFromUnmanaged("zerocopy_unmanaged_expanded", true, 10000000); } TEST(ZeroCopyFromUnmanaged, shmem_no_rc_segment) // NOLINT { - ZeroCopyFromUnmanaged("ipc://test_zerocopy_unmanaged_no_rc_segment", false, 0); + ZeroCopyFromUnmanaged("zerocopy_unmanaged_no_rc_segment", false, 0); } TEST(ZeroCopyFromUnmanaged, shmem_expanded_metadata_no_rc_segment) // NOLINT { - ZeroCopyFromUnmanaged("ipc://test_zerocopy_unmanaged_expanded_no_rc_segment", true, 0); + ZeroCopyFromUnmanaged("zerocopy_unmanaged_expanded_no_rc_segment", true, 0); } } // namespace diff --git a/test/protocols/_push_pull_multipart.cxx b/test/protocols/_push_pull_multipart.cxx index e726267d..5ed9459e 100644 --- a/test/protocols/_push_pull_multipart.cxx +++ b/test/protocols/_push_pull_multipart.cxx @@ -26,13 +26,12 @@ namespace using namespace std; using namespace fair::mq; -auto RunSingleThreadedMultipart(string transport, string address1, string address2, bool expandedShmMetadata) -> void { +auto RunSingleThreadedMultipart(string const& transport, string const& address1, string const& address2, bool expandedShmMetadata) -> void +{ fair::mq::ProgOptions config; test::Configure(config, tools::Uuid(), expandedShmMetadata); - address1 += "_" + config.GetProperty("session"); - address2 += "_" + config.GetProperty("session"); auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config); @@ -106,14 +105,13 @@ auto RunSingleThreadedMultipart(string transport, string address1, string addres } } -auto RunMultiThreadedMultipart(string transport, string address1, bool expandedShmMetadata) -> void +auto RunMultiThreadedMultipart(string const& transport, string const& address1, bool expandedShmMetadata) -> void { ProgOptions config; test::Configure(config, tools::Uuid(), expandedShmMetadata); config.SetProperty("io-threads", 1); config.SetProperty("shm-segment-size", 20000000); // NOLINT - address1 += "_" + config.GetProperty("session"); auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config); @@ -167,17 +165,20 @@ TEST(PushPull, Multipart_SingleThreaded_inproc_shmem_expanded_metadata) // NOLIN TEST(PushPull, Multipart_SingleThreaded_ipc_zeromq) // NOLINT { - RunSingleThreadedMultipart("zeromq", "ipc://test_Multipart_SingleThreaded_ipc_zeromq_1", "ipc://test_Multipart_SingleThreaded_ipc_zeromq_2", false); + test::IpcAddress const address1("multipart_1"), address2("multipart_2"); + RunSingleThreadedMultipart("zeromq", address1, address2, false); } TEST(PushPull, Multipart_SingleThreaded_ipc_shmem) // NOLINT { - RunSingleThreadedMultipart("shmem", "ipc://test_Multipart_SingleThreaded_ipc_shmem_1", "ipc://test_Multipart_SingleThreaded_ipc_shmem_2", false); + test::IpcAddress const address1("multipart_1"), address2("multipart_2"); + RunSingleThreadedMultipart("shmem", address1, address2, false); } TEST(PushPull, Multipart_SingleThreaded_ipc_shmem_expanded_metadata) // NOLINT { - RunSingleThreadedMultipart("shmem", "ipc://test_Multipart_SingleThreaded_ipc_shmem_1", "ipc://test_Multipart_SingleThreaded_ipc_shmem_2", true); + test::IpcAddress const address1("multipart_1"), address2("multipart_2"); + RunSingleThreadedMultipart("shmem", address1, address2, true); } TEST(PushPull, Multipart_MultiThreaded_inproc_zeromq) // NOLINT @@ -197,17 +198,20 @@ TEST(PushPull, Multipart_MultiThreaded_inproc_shmem_expanded_metadata) // NOLINT TEST(PushPull, Multipart_MultiThreaded_ipc_zeromq) // NOLINT { - RunMultiThreadedMultipart("zeromq", "ipc://test_Multipart_MultiThreaded_ipc_zeromq_1", false); + test::IpcAddress const address("multipart"); + RunMultiThreadedMultipart("zeromq", address, false); } TEST(PushPull, Multipart_MultiThreaded_ipc_shmem) // NOLINT { - RunMultiThreadedMultipart("shmem", "ipc://test_Multipart_MultiThreaded_ipc_shmem_1", false); + test::IpcAddress const address("multipart"); + RunMultiThreadedMultipart("shmem", address, false); } TEST(PushPull, Multipart_MultiThreaded_ipc_shmem_expanded_metadata) // NOLINT { - RunMultiThreadedMultipart("shmem", "ipc://test_Multipart_MultiThreaded_ipc_shmem__expanded_metadata_1", true); + test::IpcAddress const address("multipart"); + RunMultiThreadedMultipart("shmem", address, true); } } // namespace diff --git a/test/region/_region.cxx b/test/region/_region.cxx index b345f6b7..803865a9 100644 --- a/test/region/_region.cxx +++ b/test/region/_region.cxx @@ -85,9 +85,10 @@ void RegionsSizeMismatch() ASSERT_EQ(region2, nullptr); } -void RegionsCache(const string& transport, const string& _address) +void RegionsCache(const string& transport, const string& name) { - std::string address(tools::ToString(_address, "_", transport)); + test::IpcAddress const address1(tools::ToString(name, "_", transport, "_1")); + test::IpcAddress const address2(tools::ToString(name, "_", transport, "_2")); size_t session1 = tools::UuidHash(); size_t session2 = tools::UuidHash(); @@ -106,12 +107,12 @@ void RegionsCache(const string& transport, const string& _address) Channel push1("Push1", "push", factory1); Channel pull1("Pull1", "pull", factory1); - ASSERT_TRUE(push1.Bind(address + to_string(1))); - ASSERT_TRUE(pull1.Connect(address + to_string(1))); + ASSERT_TRUE(push1.Bind(address1)); + ASSERT_TRUE(pull1.Connect(address1)); Channel push2("Push2", "push", factory2); Channel pull2("Pull2", "pull", factory2); - ASSERT_TRUE(push2.Bind(address + to_string(2))); - ASSERT_TRUE(pull2.Connect(address + to_string(2))); + ASSERT_TRUE(push2.Bind(address2)); + ASSERT_TRUE(pull2.Connect(address2)); { static_cast(r1ptr)[0] = 97; // a @@ -260,10 +261,10 @@ void RegionEventSubscriptions(const string& transport, bool external) ASSERT_EQ(factory->SubscribedToRegionEvents(), false); } -void RegionCallbacks(const string& transport, const string& _address) +void RegionCallbacks(const string& transport, const string& name) { size_t session(tools::UuidHash()); - std::string address(tools::ToString(_address, "_", transport)); + test::IpcAddress const address(tools::ToString(name, "_", transport)); constexpr size_t sSize = 100000000; constexpr size_t r1Size = 2000000; @@ -330,13 +331,13 @@ void RegionCallbacks(const string& transport, const string& _address) LOG(info) << "2 done."; } -void RegionCallbackCallsTransportDuringDestruction(const string& transport, const string& _address) +void RegionCallbackCallsTransportDuringDestruction(const string& transport, const string& name) { // The ack callback of a region can run while the region is destroyed (outstanding acks are // delivered during the linger period). A callback that calls into the transport must not // deadlock the destruction. size_t session(tools::UuidHash()); - std::string address(tools::ToString(_address, "_", transport)); + test::IpcAddress const address(tools::ToString(name, "_", transport)); ProgOptions config; test::Configure(config, to_string(session)); @@ -366,13 +367,13 @@ void RegionCallbackCallsTransportDuringDestruction(const string& transport, cons EXPECT_EQ(numCallbacks, 1); } -void RegionLockOrder(const string& _address) +void RegionLockOrder(const string& name) { // One thread creates and destroys regions. Another thread at the same time reads messages from // regions of a different peer in the same session, which opens these regions locally. Both // paths lock the same mutexes and must lock them in the same order. size_t session(tools::UuidHash()); - std::string address(tools::ToString(_address, "_shmem")); + test::IpcAddress const address(name); constexpr int numIterations = 10; ProgOptions config; @@ -415,12 +416,12 @@ TEST(RegionsSizeMismatch, shmem) TEST(Cache, zeromq) { - RegionsCache("zeromq", "ipc://test_region_cache"); + RegionsCache("zeromq", "region_cache"); } TEST(Cache, shmem) { - RegionsCache("shmem", "ipc://test_region_cache"); + RegionsCache("shmem", "region_cache"); } TEST(EventSubscriptions, zeromq) @@ -435,27 +436,27 @@ TEST(EventSubscriptions, shmem) TEST(Callbacks, zeromq) { - RegionCallbacks("zeromq", "ipc://test_region_callbacks"); + RegionCallbacks("zeromq", "region_callbacks"); } TEST(Callbacks, shmem) { - RegionCallbacks("shmem", "ipc://test_region_callbacks"); + RegionCallbacks("shmem", "region_callbacks"); } TEST(CallbackDuringDestruction, zeromq) { - RegionCallbackCallsTransportDuringDestruction("zeromq", "ipc://test_region_callback_during_destruction"); + RegionCallbackCallsTransportDuringDestruction("zeromq", "region_callback_during_destruction"); } TEST(CallbackDuringDestruction, shmem) { - RegionCallbackCallsTransportDuringDestruction("shmem", "ipc://test_region_callback_during_destruction"); + RegionCallbackCallsTransportDuringDestruction("shmem", "region_callback_during_destruction"); } TEST(LockOrder, shmem) { - RegionLockOrder("ipc://test_region_lock_order"); + RegionLockOrder("region_lock_order"); } TEST(EventSubscriptionsExternalRegion, shmem) diff --git a/test/transport/_transfer_timeout.cxx b/test/transport/_transfer_timeout.cxx index 44e1352c..df28318a 100644 --- a/test/transport/_transfer_timeout.cxx +++ b/test/transport/_transfer_timeout.cxx @@ -69,10 +69,10 @@ auto RunTransferTimeout(string transport) -> void exit(res.exit_code); } -void InterruptTransfer(const string& transport, const string& _address) +void InterruptTransfer(const string& transport, const string& name) { size_t session{UuidHash()}; - std::string address(ToString(_address, "_", transport)); + test::IpcAddress const address(ToString(name, "_", transport)); fair::mq::ProgOptions config; test::Configure(config, to_string(session)); @@ -103,12 +103,12 @@ TEST(TransferTimeout, shmem) TEST(InterruptTransfer, zeromq) { - InterruptTransfer("zeromq", "ipc://test_interrupt_transfer"); + InterruptTransfer("zeromq", "interrupt_transfer"); } TEST(InterruptTransfer, shmem) { - InterruptTransfer("shmem", "ipc://test_interrupt_transfer"); + InterruptTransfer("shmem", "interrupt_transfer"); } } // namespace