refactor(test): set up test configs with test::Configure()

- 33 places repeated the same session, shm segment size, shm monitor
  and expanded metadata properties
- call test::Configure() and set only the properties that differ

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-03 14:14:53 +00:00
committed by Dennis Klein
parent d4a85086aa
commit 0367c2a4a8
8 changed files with 39 additions and 124 deletions

View File

@@ -11,6 +11,7 @@
#include <fairmq/Tools.h>
#include <fairmq/TransportFactory.h>
#include <helper/Sync.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <string>
@@ -98,10 +99,7 @@ TEST(Channel, Validation)
auto testConnectedPeers(std::string const& transport)
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<bool>("shm-monitor", true);
config.SetProperty<size_t>("shm-segment-size", 100000000);
string const address(tools::ToString("ipc://", config.GetProperty<string>("session")));
string const address(tools::ToString("ipc://", test::Configure(config)));
unsigned long constexpr zero(0), one(1);
auto factory(TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config));

View File

@@ -13,6 +13,7 @@
#include <boost/container/pmr/polymorphic_allocator.hpp>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <cstddef>
@@ -78,11 +79,8 @@ int TestData::ndeallocations = 0;
TEST(MemoryResources, transportAllocatorMap)
{
size_t session{tools::UuidHash()};
ProgOptions config;
config.SetProperty<string>("session", to_string(session));
config.SetProperty<bool>("shm-monitor", true);
config.SetProperty<size_t>("shm-segment-size", 100000000);
test::Configure(config);
FactoryType factoryZMQ = TransportFactory::CreateTransportFactory("zeromq", fair::mq::tools::Uuid(), &config);
FactoryType factorySHM = TransportFactory::CreateTransportFactory("shmem", fair::mq::tools::Uuid(), &config);
@@ -102,9 +100,8 @@ TEST(MemoryResources, allocator)
TestData::nallocations = 0;
TestData::ndeallocations = 0;
size_t session{tools::UuidHash()};
ProgOptions config;
config.SetProperty<std::string>("session", to_string(session));
test::Configure(config);
FactoryType factoryZMQ = TransportFactory::CreateTransportFactory("zeromq", fair::mq::tools::Uuid(), &config);
@@ -130,11 +127,8 @@ TEST(MemoryResources, getMessage)
TestData::nallocations = 0;
TestData::ndeallocations = 0;
size_t session{tools::UuidHash()};
ProgOptions config;
config.SetProperty<std::string>("session", to_string(session));
config.SetProperty<bool>("shm-monitor", true);
config.SetProperty<size_t>("shm-segment-size", 100000000);
test::Configure(config);
FactoryType factoryZMQ = TransportFactory::CreateTransportFactory("zeromq", fair::mq::tools::Uuid(), &config);
FactoryType factorySHM = TransportFactory::CreateTransportFactory("shmem", fair::mq::tools::Uuid(), &config);

View File

@@ -17,6 +17,7 @@
#include <helper/Sync.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <array>
@@ -45,12 +46,7 @@ auto AsStringView(Message const& msg) -> string_view
auto RunPushPullWithMsgResize(string const & transport, string const & _address, bool expandedShmMetadata = false) -> void
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
if (expandedShmMetadata) {
config.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
test::Configure(config, tools::Uuid(), expandedShmMetadata);
auto factory(TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config));
Channel push{"Push", "push", factory};
@@ -111,12 +107,7 @@ auto RunPushPullWithMsgResize(string const & transport, string const & _address,
auto RunMsgRebuild(const string& transport, bool expandedShmMetadata = false) -> void
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
if (expandedShmMetadata) {
config.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
test::Configure(config, tools::Uuid(), expandedShmMetadata);
auto factory(TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config));
size_t const msgSize{100};
@@ -148,12 +139,7 @@ auto CheckMsgAlignment(Message const& msg, fair::mq::Alignment alignment) -> boo
auto RunPushPullWithAlignment(string const& transport, string const& _address, bool expandedShmMetadata = false) -> void
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
if (expandedShmMetadata) {
config.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
test::Configure(config, tools::Uuid(), expandedShmMetadata);
auto factory(TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config));
Channel push{"Push", "push", factory};
@@ -206,12 +192,7 @@ auto RunPushPullWithAlignment(string const& transport, string const& _address, b
auto EmptyMessage(string const& transport, string const& _address, bool expandedShmMetadata = false) -> void
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
if (expandedShmMetadata) {
config.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
test::Configure(config, tools::Uuid(), expandedShmMetadata);
auto factory(TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config));
Channel push{"Push", "push", factory};
@@ -261,12 +242,7 @@ auto EmptyMessage(string const& transport, string const& _address, bool expanded
auto ZeroCopy(bool expandedShmMetadata = false) -> void
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
if (expandedShmMetadata) {
config.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
test::Configure(config, tools::Uuid(), expandedShmMetadata);
auto factory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &config));
unique_ptr<string> str(make_unique<string>("asdf"));
@@ -296,21 +272,10 @@ auto ZeroCopyFromUnmanaged(string const& address, bool expandedShmMetadata, uint
{
ProgOptions config1;
ProgOptions config2;
string session(tools::Uuid());
config1.SetProperty<string>("session", session);
config1.SetProperty<size_t>("shm-segment-size", 100000000);
config1.SetProperty<bool>("shm-monitor", true);
config2.SetProperty<string>("session", session);
config2.SetProperty<size_t>("shm-segment-size", 100000000);
config2.SetProperty<bool>("shm-monitor", true);
string const session(test::Configure(config1, tools::Uuid(), expandedShmMetadata));
test::Configure(config2, session, expandedShmMetadata);
// ref counts should be accessible accross different segments
config2.SetProperty<uint16_t>("shm-segment-id", 2);
if (expandedShmMetadata) {
config1.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
if (expandedShmMetadata) {
config2.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
auto factory1(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &config1));
auto factory2(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &config2));
@@ -464,18 +429,11 @@ auto SideChannel(bool expandedShmMetadata = false) -> void
const string session = tools::Uuid();
ProgOptions producerConfig;
producerConfig.SetProperty<string>("session", session);
producerConfig.SetProperty<size_t>("shm-segment-size", 100000000);
producerConfig.SetProperty<bool>("shm-monitor", true);
if (expandedShmMetadata) {
producerConfig.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
test::Configure(producerConfig, session, expandedShmMetadata);
auto producerFactory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &producerConfig));
ProgOptions consumerConfig;
consumerConfig.SetProperty<string>("session", session);
consumerConfig.SetProperty<size_t>("shm-segment-size", 100000000);
consumerConfig.SetProperty<bool>("shm-monitor", true);
test::Configure(consumerConfig, session);
auto consumerFactory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &consumerConfig));
const size_t size = 2;
@@ -512,15 +470,11 @@ auto SideChannelUnmanaged() -> void
const string session = tools::Uuid();
ProgOptions producerConfig;
producerConfig.SetProperty<string>("session", session);
producerConfig.SetProperty<size_t>("shm-segment-size", 100000000);
producerConfig.SetProperty<bool>("shm-monitor", true);
test::Configure(producerConfig, session);
auto producerFactory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &producerConfig));
ProgOptions consumerConfig;
consumerConfig.SetProperty<string>("session", session);
consumerConfig.SetProperty<size_t>("shm-segment-size", 100000000);
consumerConfig.SetProperty<bool>("shm-monitor", true);
test::Configure(consumerConfig, session);
auto consumerFactory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &consumerConfig));
const size_t regionSize = 1000000;
@@ -552,9 +506,7 @@ auto SideChannelUnmanaged() -> void
auto ReuseReceivedRegionMessage() -> void
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
test::Configure(config);
auto factory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &config));
const size_t regionSize = 1000000;
@@ -599,9 +551,7 @@ auto ReuseReceivedRegionMessage() -> void
auto SideChannelErrors() -> void
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
test::Configure(config);
auto shmFactory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &config));
auto zmqFactory(TransportFactory::CreateTransportFactory("zeromq", tools::Uuid(), &config));

View File

@@ -13,6 +13,7 @@
#include <fairmq/ProgOptions.h>
#include <fairmq/TransportFactory.h>
#include <fairmq/tools/Unique.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <memory>
#include <sstream>
@@ -28,12 +29,7 @@ using namespace fair::mq;
auto RunSingleThreadedMultipart(string transport, string address1, string address2, bool expandedShmMetadata) -> void {
fair::mq::ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
if (expandedShmMetadata) {
config.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
test::Configure(config, tools::Uuid(), expandedShmMetadata);
address1 += "_" + config.GetProperty<string>("session");
address2 += "_" + config.GetProperty<string>("session");
@@ -113,13 +109,9 @@ auto RunSingleThreadedMultipart(string transport, string address1, string addres
auto RunMultiThreadedMultipart(string transport, string address1, bool expandedShmMetadata) -> void
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
test::Configure(config, tools::Uuid(), expandedShmMetadata);
config.SetProperty<int>("io-threads", 1);
config.SetProperty<size_t>("shm-segment-size", 20000000); // NOLINT
config.SetProperty<bool>("shm-monitor", true);
if (expandedShmMetadata) {
config.SetProperty<size_t>("shm-metadata-msg-size", 2048);
}
address1 += "_" + config.GetProperty<string>("session");

View File

@@ -20,6 +20,7 @@
#include <helper/Sync.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <atomic>
@@ -70,9 +71,7 @@ void RegionsSizeMismatch()
size_t session = tools::UuidHash();
ProgOptions config;
config.SetProperty<string>("session", to_string(session));
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
test::Configure(config, to_string(session));
auto factory = TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &config);
@@ -94,12 +93,8 @@ void RegionsCache(const string& transport, const string& _address)
ProgOptions config1;
ProgOptions config2;
config1.SetProperty<string>("session", to_string(session1));
config1.SetProperty<size_t>("shm-segment-size", 100000000);
config1.SetProperty<bool>("shm-monitor", true);
config2.SetProperty<string>("session", to_string(session2));
config2.SetProperty<size_t>("shm-segment-size", 100000000);
config2.SetProperty<bool>("shm-monitor", true);
test::Configure(config1, to_string(session1));
test::Configure(config2, to_string(session2));
auto factory1 = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config1);
auto factory2 = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config2);
@@ -174,9 +169,8 @@ void RegionEventSubscriptions(const string& transport, bool external)
}
ProgOptions config;
config.SetProperty<string>("session", to_string(session));
test::Configure(config, to_string(session));
config.SetProperty<size_t>("shm-segment-size", sSize);
config.SetProperty<bool>("shm-monitor", true);
if (external) {
config.SetProperty<bool>("shm-no-cleanup", true);
// config.SetProperty<bool>("shm-monitor", false);
@@ -276,9 +270,8 @@ void RegionCallbacks(const string& transport, const string& _address)
constexpr size_t r2Size = 3000000;
ProgOptions config;
config.SetProperty<string>("session", to_string(session));
test::Configure(config, to_string(session));
config.SetProperty<size_t>("shm-segment-size", sSize);
config.SetProperty<bool>("shm-monitor", true);
auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config);
@@ -346,9 +339,7 @@ void RegionCallbackCallsTransportDuringDestruction(const string& transport, cons
std::string address(tools::ToString(_address, "_", transport));
ProgOptions config;
config.SetProperty<string>("session", to_string(session));
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
test::Configure(config, to_string(session));
auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config);
@@ -385,9 +376,7 @@ void RegionLockOrder(const string& _address)
constexpr int numIterations = 10;
ProgOptions config;
config.SetProperty<string>("session", to_string(session));
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
test::Configure(config, to_string(session));
auto factory1 = TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &config);
auto factory2 = TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &config);

View File

@@ -14,6 +14,7 @@
#include <fairmq/ProgOptions.h>
#include <fairmq/TransportFactory.h>
#include <fairmq/tools/Unique.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <memory>
#include <sstream>
@@ -40,9 +41,7 @@ void CheckOldOptionInterface(Channel& channel, const string& option)
void RunOptionsTest(const string& transport)
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
config.SetProperty<bool>("shm-monitor", true);
config.SetProperty<size_t>("shm-segment-size", 100000000);
test::Configure(config);
auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config);
Channel channel("Push", "push", factory);
@@ -72,11 +71,10 @@ void RunOptionsTest(const string& transport)
void ZeroingAndMlock(const string& transport)
{
ProgOptions config;
config.SetProperty<string>("session", tools::Uuid());
test::Configure(config);
config.SetProperty<size_t>("shm-segment-size", 16384); // NOLINT
config.SetProperty<bool>("shm-zero-segment", true);
config.SetProperty<bool>("shm-mlock-segment", true);
config.SetProperty<bool>("shm-monitor", true);
auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config);
@@ -88,14 +86,11 @@ void ZeroingAndMlock(const string& transport)
void ZeroingAndMlockOnCreation(const string& transport)
{
size_t session{tools::UuidHash()};
ProgOptions config;
config.SetProperty<string>("session", to_string(session));
test::Configure(config);
config.SetProperty<size_t>("shm-segment-size", 16384); // NOLINT
config.SetProperty<bool>("shm-mlock-segment-on-creation", true);
config.SetProperty<bool>("shm-zero-segment-on-creation", true);
config.SetProperty<bool>("shm-monitor", true);
auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config);

View File

@@ -11,6 +11,7 @@
#include <fairmq/tools/Unique.h>
#include <fairmq/TransportFactory.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <string>
@@ -24,10 +25,7 @@ using namespace fair::mq;
void GetFreeMemory()
{
ProgOptions config;
string sessionId(to_string(tools::UuidHash()));
config.SetProperty<string>("session", sessionId);
config.SetProperty<bool>("shm-monitor", true);
config.SetProperty<size_t>("shm-segment-size", 100000000);
string const sessionId(test::Configure(config));
ASSERT_THROW(shmem::Monitor::GetFreeMemory(shmem::SessionId{sessionId}, 0), shmem::Monitor::MonitorError);

View File

@@ -17,6 +17,7 @@
#include <fairlogger/Logger.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <chrono>
@@ -74,9 +75,7 @@ void InterruptTransfer(const string& transport, const string& _address)
std::string address(ToString(_address, "_", transport));
fair::mq::ProgOptions config;
config.SetProperty<string>("session", to_string(session));
config.SetProperty<size_t>("shm-segment-size", 100000000);
config.SetProperty<bool>("shm-monitor", true);
test::Configure(config, to_string(session));
auto factory = TransportFactory::CreateTransportFactory(transport, Uuid(), &config);