Skip to content

Commit d9b8b72

Browse files
add unit test
1 parent c65bfbb commit d9b8b72

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

src/controller/tests/data_model/TestRead.cpp

+76
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,82 @@ TEST_F(TestRead, TestResubscribeAttributeTimeout)
15291529
EXPECT_EQ(GetExchangeManager().GetNumActiveExchanges(), 0u);
15301530
}
15311531

1532+
TEST_F(TestRead, TestShutdownAllSubscriptionHandlers)
1533+
{
1534+
auto sessionHandle = GetSessionBobToAlice();
1535+
1536+
SetMRPMode(MessagingContext::MRPMode::kResponsive);
1537+
1538+
{
1539+
TestResubscriptionCallback callback;
1540+
ReadClient readClient(InteractionModelEngine::GetInstance(), &GetExchangeManager(), callback,
1541+
ReadClient::InteractionType::Subscribe);
1542+
1543+
callback.SetReadClient(&readClient);
1544+
1545+
ReadPrepareParams readPrepareParams(GetSessionBobToAlice());
1546+
1547+
// Read full wildcard paths, repeat twice to ensure chunking.
1548+
AttributePathParams attributePathParams[1];
1549+
readPrepareParams.mpAttributePathParamsList = attributePathParams;
1550+
readPrepareParams.mAttributePathParamsListSize = MATTER_ARRAY_SIZE(attributePathParams);
1551+
attributePathParams[0].mEndpointId = kTestEndpointId;
1552+
attributePathParams[0].mClusterId = Clusters::UnitTesting::Id;
1553+
attributePathParams[0].mAttributeId = Clusters::UnitTesting::Attributes::Boolean::Id;
1554+
1555+
constexpr uint16_t maxIntervalCeilingSeconds = 1;
1556+
1557+
readPrepareParams.mMaxIntervalCeilingSeconds = maxIntervalCeilingSeconds;
1558+
1559+
auto err = readClient.SendAutoResubscribeRequest(std::move(readPrepareParams));
1560+
EXPECT_EQ(err, CHIP_NO_ERROR);
1561+
1562+
//
1563+
// Drive servicing IO till we have established a subscription.
1564+
//
1565+
GetIOContext().DriveIOUntil(System::Clock::Milliseconds32(2000),
1566+
[&]() { return callback.mOnSubscriptionEstablishedCount >= 1; });
1567+
EXPECT_EQ(callback.mOnSubscriptionEstablishedCount, 1);
1568+
EXPECT_EQ(callback.mOnError, 0);
1569+
EXPECT_EQ(callback.mOnResubscriptionsAttempted, 0);
1570+
1571+
1572+
InteractionModelEngine::GetInstance()->ShutdownAllSubscriptionHandlers();
1573+
1574+
ReadHandler * readHandler = InteractionModelEngine::GetInstance()->ActiveHandlerAt(0);
1575+
1576+
uint16_t minInterval;
1577+
uint16_t maxInterval;
1578+
readHandler->GetReportingIntervals(minInterval, maxInterval);
1579+
GetIOContext().DriveIOUntil(ComputeSubscriptionTimeout(System::Clock::Seconds16(maxInterval)),
1580+
[&]() { return callback.mOnResubscriptionsAttempted > 0; });
1581+
1582+
EXPECT_EQ(callback.mOnResubscriptionsAttempted, 1);
1583+
EXPECT_EQ(callback.mLastError, CHIP_ERROR_TIMEOUT);
1584+
1585+
GetLoopback().mNumMessagesToDrop = 0;
1586+
callback.ClearCounters();
1587+
1588+
//
1589+
// Drive servicing IO till we have established a subscription.
1590+
//
1591+
GetIOContext().DriveIOUntil(System::Clock::Milliseconds32(2000),
1592+
[&]() { return callback.mOnSubscriptionEstablishedCount == 1; });
1593+
EXPECT_EQ(callback.mOnSubscriptionEstablishedCount, 1);
1594+
1595+
//
1596+
// With re-sub enabled, we shouldn't have encountered any errors
1597+
//
1598+
EXPECT_EQ(callback.mOnError, 0);
1599+
EXPECT_EQ(callback.mOnDone, 0);
1600+
}
1601+
1602+
SetMRPMode(MessagingContext::MRPMode::kDefault);
1603+
1604+
InteractionModelEngine::GetInstance()->ShutdownAllSubscriptions();
1605+
EXPECT_EQ(GetExchangeManager().GetNumActiveExchanges(), 0u);
1606+
}
1607+
15321608
//
15331609
// This validates a vanilla subscription with re-susbcription disabled timing out correctly on the client
15341610
// side and triggering the OnError callback with the right error code.

0 commit comments

Comments
 (0)