Skip to content

Commit 1756691

Browse files
committed
Fix bug and get 100% coverage again
1 parent ac4cb60 commit 1756691

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/app/server-cluster/ServerClusterInterfaceRegistry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ServerClusterInterfaceRegistry::~ServerClusterInterfaceRegistry()
3434
{
3535
for (auto & ep : mPreallocateEndpoints)
3636
{
37-
if (ep.endpointId == kInvalidEndpointId)
37+
if (ep.endpointId != kInvalidEndpointId)
3838
{
3939
UnregisterAllFromEndpoint(ep.endpointId);
4040
}

src/app/server-cluster/tests/TestServerClusterInterfaceRegistry.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,38 @@ TEST_F(TestServerClusterInterfaceRegistry, StressTest)
267267
}
268268
}
269269

270+
TEST_F(TestServerClusterInterfaceRegistry, TestDestructionOrder)
271+
{
272+
// Test that registry destruction AFTER clusters is still ok
273+
std::vector<FakeServerClusterInterface> items;
274+
static constexpr ClusterId kClusterTestCount = 200;
275+
276+
items.reserve(kClusterTestCount);
277+
for (ClusterId i = 0; i < kClusterTestCount; i++)
278+
{
279+
items.emplace_back(i);
280+
ASSERT_FALSE(items[i].IsInList());
281+
}
282+
283+
{
284+
ServerClusterInterfaceRegistry registry;
285+
286+
for (ClusterId i = 0; i < kClusterTestCount; i++)
287+
{
288+
ASSERT_EQ(registry.Register(static_cast<EndpointId>(i % 10), &items[i]), CHIP_NO_ERROR);
289+
}
290+
for (ClusterId i = 0; i < kClusterTestCount; i++)
291+
{
292+
ASSERT_TRUE(items[i].IsInList());
293+
}
294+
}
295+
296+
for (ClusterId i = 0; i < kClusterTestCount; i++)
297+
{
298+
ASSERT_FALSE(items[i].IsInList());
299+
}
300+
}
301+
270302
TEST_F(TestServerClusterInterfaceRegistry, InstanceUsage)
271303
{
272304
// This tests uses the instance member, to get coverage

0 commit comments

Comments
 (0)