@@ -1529,6 +1529,82 @@ TEST_F(TestRead, TestResubscribeAttributeTimeout)
1529
1529
EXPECT_EQ (GetExchangeManager ().GetNumActiveExchanges (), 0u );
1530
1530
}
1531
1531
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
+
1532
1608
//
1533
1609
// This validates a vanilla subscription with re-susbcription disabled timing out correctly on the client
1534
1610
// side and triggering the OnError callback with the right error code.
0 commit comments