mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 21:21:37 +00:00
fix(test): fail instead of hang when a region callback check fails
- an ASSERT_* in a region callback returned before blocker.Signal(), and the test then waited in blocker.Wait() until the ctest timeout - use EXPECT_* in the callbacks, so that the signal always comes - wait with a deadline (test::Semaphore) in the region and message tests - in RegionEventSubscriptions, make the semaphore outlive the factory that calls the callback Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include <fairmq/Channel.h>
|
#include <fairmq/Channel.h>
|
||||||
#include <fairmq/ProgOptions.h>
|
#include <fairmq/ProgOptions.h>
|
||||||
#include <fairmq/tools/Semaphore.h>
|
|
||||||
#include <fairmq/tools/Strings.h>
|
#include <fairmq/tools/Strings.h>
|
||||||
#include <fairmq/tools/Unique.h>
|
#include <fairmq/tools/Unique.h>
|
||||||
#include <fairmq/TransportFactory.h>
|
#include <fairmq/TransportFactory.h>
|
||||||
@@ -16,6 +15,8 @@
|
|||||||
|
|
||||||
#include <fairlogger/Logger.h>
|
#include <fairlogger/Logger.h>
|
||||||
|
|
||||||
|
#include <helper/Sync.h>
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
@@ -317,7 +318,7 @@ auto ZeroCopyFromUnmanaged(string const& address, bool expandedShmMetadata, uint
|
|||||||
const size_t regionSize{1000000};
|
const size_t regionSize{1000000};
|
||||||
RegionConfig cfg;
|
RegionConfig cfg;
|
||||||
cfg.rcSegmentSize = rcSegmentSize;
|
cfg.rcSegmentSize = rcSegmentSize;
|
||||||
tools::Semaphore blocker;
|
test::Semaphore blocker;
|
||||||
|
|
||||||
auto region = factory1->CreateUnmanagedRegion(regionSize, [&blocker](void*, size_t, void*) {
|
auto region = factory1->CreateUnmanagedRegion(regionSize, [&blocker](void*, size_t, void*) {
|
||||||
blocker.Signal();
|
blocker.Signal();
|
||||||
@@ -391,8 +392,8 @@ auto ZeroCopyFromUnmanaged(string const& address, bool expandedShmMetadata, uint
|
|||||||
EXPECT_EQ(static_cast<const shmem::Message&>(*msg1).GetRefCount(), 1);
|
EXPECT_EQ(static_cast<const shmem::Message&>(*msg1).GetRefCount(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Resize, zeromq) // NOLINT
|
TEST(Resize, zeromq) // NOLINT
|
||||||
@@ -523,7 +524,7 @@ auto SideChannelUnmanaged() -> void
|
|||||||
auto consumerFactory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &consumerConfig));
|
auto consumerFactory(TransportFactory::CreateTransportFactory("shmem", tools::Uuid(), &consumerConfig));
|
||||||
|
|
||||||
const size_t regionSize = 1000000;
|
const size_t regionSize = 1000000;
|
||||||
tools::Semaphore blocker;
|
test::Semaphore blocker;
|
||||||
auto region = producerFactory->CreateUnmanagedRegion(regionSize, [&blocker](void*, size_t, void*) {
|
auto region = producerFactory->CreateUnmanagedRegion(regionSize, [&blocker](void*, size_t, void*) {
|
||||||
blocker.Signal();
|
blocker.Signal();
|
||||||
});
|
});
|
||||||
@@ -545,7 +546,7 @@ auto SideChannelUnmanaged() -> void
|
|||||||
EXPECT_EQ(ptr[1], 'B');
|
EXPECT_EQ(ptr[1], 'B');
|
||||||
|
|
||||||
msg.reset();
|
msg.reset();
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ReuseReceivedRegionMessage() -> void
|
auto ReuseReceivedRegionMessage() -> void
|
||||||
|
|||||||
@@ -14,11 +14,12 @@
|
|||||||
#include <fairmq/TransportFactory.h>
|
#include <fairmq/TransportFactory.h>
|
||||||
#include <fairmq/ProgOptions.h>
|
#include <fairmq/ProgOptions.h>
|
||||||
#include <fairmq/tools/Unique.h>
|
#include <fairmq/tools/Unique.h>
|
||||||
#include <fairmq/tools/Semaphore.h>
|
|
||||||
#include <fairmq/tools/Strings.h>
|
#include <fairmq/tools/Strings.h>
|
||||||
|
|
||||||
#include <fairlogger/Logger.h>
|
#include <fairlogger/Logger.h>
|
||||||
|
|
||||||
|
#include <helper/Sync.h>
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
@@ -181,10 +182,11 @@ void RegionEventSubscriptions(const string& transport, bool external)
|
|||||||
// config.SetProperty<bool>("shm-monitor", false);
|
// config.SetProperty<bool>("shm-monitor", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// outlives the factory, which can call the event callback until it is destroyed
|
||||||
|
test::Semaphore blocker;
|
||||||
auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config);
|
auto factory = TransportFactory::CreateTransportFactory(transport, tools::Uuid(), &config);
|
||||||
|
|
||||||
constexpr int64_t userFlags = 12345;
|
constexpr int64_t userFlags = 12345;
|
||||||
tools::Semaphore blocker;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
fair::mq::RegionConfig r1Cfg;
|
fair::mq::RegionConfig r1Cfg;
|
||||||
@@ -224,14 +226,14 @@ void RegionEventSubscriptions(const string& transport, bool external)
|
|||||||
<< ", flags: " << info.flags;
|
<< ", flags: " << info.flags;
|
||||||
if (info.event == RegionEvent::created) {
|
if (info.event == RegionEvent::created) {
|
||||||
if (info.id == id1) {
|
if (info.id == id1) {
|
||||||
ASSERT_EQ(info.size, r1Size);
|
EXPECT_EQ(info.size, r1Size);
|
||||||
ASSERT_EQ(info.ptr, ptr1);
|
EXPECT_EQ(info.ptr, ptr1);
|
||||||
blocker.Signal();
|
blocker.Signal();
|
||||||
} else if (info.id == id2) {
|
} else if (info.id == id2) {
|
||||||
ASSERT_EQ(info.size, r2Size);
|
EXPECT_EQ(info.size, r2Size);
|
||||||
ASSERT_EQ(info.ptr, ptr2);
|
EXPECT_EQ(info.ptr, ptr2);
|
||||||
if (!external) {
|
if (!external) {
|
||||||
ASSERT_EQ(info.flags, userFlags);
|
EXPECT_EQ(info.flags, userFlags);
|
||||||
}
|
}
|
||||||
blocker.Signal();
|
blocker.Signal();
|
||||||
}
|
}
|
||||||
@@ -246,16 +248,16 @@ void RegionEventSubscriptions(const string& transport, bool external)
|
|||||||
ASSERT_EQ(factory->SubscribedToRegionEvents(), true);
|
ASSERT_EQ(factory->SubscribedToRegionEvents(), true);
|
||||||
|
|
||||||
LOG(info) << "waiting for blockers...";
|
LOG(info) << "waiting for blockers...";
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
LOG(info) << "1 done.";
|
LOG(info) << "1 done.";
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
LOG(info) << "2 done.";
|
LOG(info) << "2 done.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!external) {
|
if (!external) {
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
LOG(info) << "3 done.";
|
LOG(info) << "3 done.";
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
LOG(info) << "4 done.";
|
LOG(info) << "4 done.";
|
||||||
}
|
}
|
||||||
LOG(info) << "All done.";
|
LOG(info) << "All done.";
|
||||||
@@ -282,7 +284,7 @@ void RegionCallbacks(const string& transport, const string& _address)
|
|||||||
|
|
||||||
unique_ptr<int> intPtr1 = make_unique<int>(42);
|
unique_ptr<int> intPtr1 = make_unique<int>(42);
|
||||||
unique_ptr<int> intPtr2 = make_unique<int>(43);
|
unique_ptr<int> intPtr2 = make_unique<int>(43);
|
||||||
tools::Semaphore blocker;
|
test::Semaphore blocker;
|
||||||
|
|
||||||
Channel push("Push", "push", factory);
|
Channel push("Push", "push", factory);
|
||||||
ASSERT_TRUE(push.Bind(address));
|
ASSERT_TRUE(push.Bind(address));
|
||||||
@@ -296,20 +298,20 @@ void RegionCallbacks(const string& transport, const string& _address)
|
|||||||
size_t size2 = 200;
|
size_t size2 = 200;
|
||||||
|
|
||||||
auto region1 = factory->CreateUnmanagedRegion(r1Size, [&](void* ptr, size_t size, void* hint) {
|
auto region1 = factory->CreateUnmanagedRegion(r1Size, [&](void* ptr, size_t size, void* hint) {
|
||||||
ASSERT_EQ(ptr, ptr1);
|
EXPECT_EQ(ptr, ptr1);
|
||||||
ASSERT_EQ(size, size1);
|
EXPECT_EQ(size, size1);
|
||||||
ASSERT_EQ(hint, intPtr1.get());
|
EXPECT_EQ(hint, intPtr1.get());
|
||||||
ASSERT_EQ(*static_cast<int*>(hint), 42);
|
EXPECT_EQ(*static_cast<int*>(hint), 42);
|
||||||
blocker.Signal();
|
blocker.Signal();
|
||||||
});
|
});
|
||||||
ptr1 = region1->GetData();
|
ptr1 = region1->GetData();
|
||||||
|
|
||||||
auto region2 = factory->CreateUnmanagedRegion(r2Size, [&](const std::vector<RegionBlock>& blocks) {
|
auto region2 = factory->CreateUnmanagedRegion(r2Size, [&](const std::vector<RegionBlock>& blocks) {
|
||||||
ASSERT_EQ(blocks.size(), 1);
|
EXPECT_EQ(blocks.size(), 1);
|
||||||
ASSERT_EQ(blocks.at(0).ptr, ptr2);
|
EXPECT_EQ(blocks.at(0).ptr, ptr2);
|
||||||
ASSERT_EQ(blocks.at(0).size, size2);
|
EXPECT_EQ(blocks.at(0).size, size2);
|
||||||
ASSERT_EQ(blocks.at(0).hint, intPtr2.get());
|
EXPECT_EQ(blocks.at(0).hint, intPtr2.get());
|
||||||
ASSERT_EQ(*static_cast<int*>(blocks.at(0).hint), 43);
|
EXPECT_EQ(*static_cast<int*>(blocks.at(0).hint), 43);
|
||||||
blocker.Signal();
|
blocker.Signal();
|
||||||
});
|
});
|
||||||
ptr2 = region2->GetData();
|
ptr2 = region2->GetData();
|
||||||
@@ -329,9 +331,9 @@ void RegionCallbacks(const string& transport, const string& _address)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG(info) << "waiting for blockers...";
|
LOG(info) << "waiting for blockers...";
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
LOG(info) << "1 done.";
|
LOG(info) << "1 done.";
|
||||||
blocker.Wait();
|
ASSERT_TRUE(blocker.Wait());
|
||||||
LOG(info) << "2 done.";
|
LOG(info) << "2 done.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user