Skip to content

Commit 276d01a

Browse files
add test
1 parent 10db778 commit 276d01a

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/app/ReadClient.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ void ReadClient::OnActiveModeNotification()
494494
}
495495

496496
TriggerResubscribeIfScheduled("check-in message");
497-
return;
498497
}
499498

500499
void ReadClient::OnPeerTypeChange(PeerType aType)

src/controller/tests/data_model/TestRead.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,73 @@ TEST_F(TestRead, TestSubscribe_OnActiveModeNotification)
23542354
EXPECT_EQ(GetExchangeManager().GetNumActiveExchanges(), 0u);
23552355
}
23562356

2357+
TEST_F(TestRead, TestSubscribeFailed_OnActiveModeNotification)
2358+
{
2359+
auto sessionHandle = GetSessionBobToAlice();
2360+
2361+
SetMRPMode(MessagingContext::MRPMode::kResponsive);
2362+
2363+
{
2364+
TestResubscriptionCallback callback;
2365+
ReadClient readClient(InteractionModelEngine::GetInstance(), &GetExchangeManager(), callback,
2366+
ReadClient::InteractionType::Subscribe);
2367+
2368+
callback.mScheduleLITResubscribeImmediately = false;
2369+
callback.SetReadClient(&readClient);
2370+
2371+
ReadPrepareParams readPrepareParams(GetSessionBobToAlice());
2372+
2373+
AttributePathParams attributePathParams[1];
2374+
readPrepareParams.mpAttributePathParamsList = attributePathParams;
2375+
readPrepareParams.mAttributePathParamsListSize = MATTER_ARRAY_SIZE(attributePathParams);
2376+
attributePathParams[0].mEndpointId = kTestEndpointId;
2377+
attributePathParams[0].mClusterId = Clusters::UnitTesting::Id;
2378+
attributePathParams[0].mAttributeId = Clusters::UnitTesting::Attributes::Boolean::Id;
2379+
2380+
constexpr uint16_t maxIntervalCeilingSeconds = 1;
2381+
2382+
readPrepareParams.mMaxIntervalCeilingSeconds = maxIntervalCeilingSeconds;
2383+
readPrepareParams.mIsPeerLIT = true;
2384+
2385+
auto err = readClient.SendAutoResubscribeRequest(std::move(readPrepareParams));
2386+
EXPECT_EQ(err, CHIP_NO_ERROR);
2387+
2388+
GetLoopback().mNumMessagesToDrop = LoopbackTransport::kUnlimitedMessageCount;
2389+
GetIOContext().DriveIOUntil(System::Clock::Milliseconds32(3000),
2390+
[&]() { return callback.mOnResubscriptionsAttempted == 1; });
2391+
EXPECT_EQ(callback.mOnSubscriptionEstablishedCount, 0);
2392+
2393+
GetIOContext().DriveIOUntil(System::Clock::Milliseconds32(3000),
2394+
[&]() { return callback.mOnResubscriptionsAttempted == 2; });
2395+
EXPECT_EQ(callback.mOnSubscriptionEstablishedCount, 0);
2396+
2397+
GetLoopback().mNumMessagesToDrop = 0;
2398+
callback.ClearCounters();
2399+
InteractionModelEngine::GetInstance()->OnActiveModeNotification(
2400+
ScopedNodeId(readClient.GetPeerNodeId(), readClient.GetFabricIndex()));
2401+
//
2402+
// Drive servicing IO till we have established a subscription.
2403+
//
2404+
GetIOContext().DriveIOUntil(System::Clock::Milliseconds32(2000),
2405+
[&]() { return callback.mOnSubscriptionEstablishedCount == 1; });
2406+
EXPECT_EQ(callback.mOnSubscriptionEstablishedCount, 1);
2407+
2408+
//
2409+
// With re-sub enabled, we shouldn't have encountered any errors
2410+
//
2411+
EXPECT_EQ(callback.mOnError, 0);
2412+
EXPECT_EQ(callback.mOnDone, 0);
2413+
2414+
GetLoopback().mNumMessagesToDrop = 0;
2415+
callback.ClearCounters();
2416+
}
2417+
2418+
SetMRPMode(MessagingContext::MRPMode::kDefault);
2419+
2420+
InteractionModelEngine::GetInstance()->ShutdownActiveReads();
2421+
EXPECT_EQ(GetExchangeManager().GetNumActiveExchanges(), 0u);
2422+
}
2423+
23572424
/**
23582425
* When the liveness timeout of a subscription to ICD is reached, the subscription will enter "InactiveICDSubscription" state, the
23592426
* client should call "OnActiveModeNotification" to re-activate it again when the check-in message is received from the ICD.

0 commit comments

Comments
 (0)