Skip to content

Commit af19062

Browse files
[Chef] update chef force check-in command with shutdown all subs (#38072)
* update chef force check-in command with shutdown all subs * update * address comments * add unit test * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 6cef5da commit af19062

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

examples/common/pigweed/rpc_services/Device.h

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
487487
#if CHIP_CONFIG_ENABLE_ICD_CIP
488488
chip::DeviceLayer::PlatformMgr().ScheduleWork(
489489
[](intptr_t) {
490+
chip::app::InteractionModelEngine::GetInstance()->ShutdownAllSubscriptionHandlers();
490491
ChipLogDetail(AppServer, "Being triggerred to send ICD check-in message to subscriber");
491492
chip::app::ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
492493
},

src/app/InteractionModelEngine.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,18 @@ void InteractionModelEngine::ShutdownAllSubscriptions()
387387
ShutdownMatchingSubscriptions();
388388
}
389389

390+
void InteractionModelEngine::ShutdownAllSubscriptionHandlers()
391+
{
392+
mReadHandlers.ForEachActiveObject([&](auto * handler) {
393+
if (!handler->IsType(ReadHandler::InteractionType::Subscribe))
394+
{
395+
return Loop::Continue;
396+
}
397+
handler->Close();
398+
return Loop::Continue;
399+
});
400+
}
401+
390402
void InteractionModelEngine::ShutdownMatchingSubscriptions(const Optional<FabricIndex> & aFabricIndex,
391403
const Optional<NodeId> & aPeerNodeId)
392404
{

src/app/InteractionModelEngine.h

+6
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,14 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
169169
* Tears down all active subscriptions.
170170
*/
171171
void ShutdownAllSubscriptions();
172+
172173
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
173174

175+
/**
176+
* Tears down all subscription handlers.
177+
*/
178+
void ShutdownAllSubscriptionHandlers();
179+
174180
uint32_t GetNumActiveReadHandlers() const;
175181
uint32_t GetNumActiveReadHandlers(ReadHandler::InteractionType type) const;
176182

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+
ReadHandler * readHandler = InteractionModelEngine::GetInstance()->ActiveHandlerAt(0);
1572+
1573+
uint16_t minInterval;
1574+
uint16_t maxInterval;
1575+
readHandler->GetReportingIntervals(minInterval, maxInterval);
1576+
1577+
InteractionModelEngine::GetInstance()->ShutdownAllSubscriptionHandlers();
1578+
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()->ShutdownActiveReads();
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)