Skip to content

Commit b01695e

Browse files
add mNumReportsInFlight check test when failing to send report (#24106)
1 parent 245a7f4 commit b01695e

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/app/tests/TestReadInteraction.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ class TestReadInteraction
319319
static void TestSubscribeRoundtripStatusReportTimeout(nlTestSuite * apSuite, void * apContext);
320320
static void TestPostSubscribeRoundtripStatusReportTimeout(nlTestSuite * apSuite, void * apContext);
321321
static void TestReadChunkingStatusReportTimeout(nlTestSuite * apSuite, void * apContext);
322+
static void TestReadReportFailure(nlTestSuite * apSuite, void * apContext);
322323
static void TestSubscribeRoundtripChunkStatusReportTimeout(nlTestSuite * apSuite, void * apContext);
323324
static void TestPostSubscribeRoundtripChunkStatusReportTimeout(nlTestSuite * apSuite, void * apContext);
324325
static void TestPostSubscribeRoundtripChunkReportTimeout(nlTestSuite * apSuite, void * apContext);
@@ -2531,6 +2532,57 @@ void TestReadInteraction::TestReadChunkingStatusReportTimeout(nlTestSuite * apSu
25312532
ctx.CreateSessionBobToAlice();
25322533
}
25332534

2535+
// ReadClient sends the read request, but handler fails to send the one report (SendMessage returns an error).
2536+
// Since this is an un-chunked read, we are not in the AwaitingReportResponse state, so the "reports in flight"
2537+
// counter should not increase.
2538+
void TestReadInteraction::TestReadReportFailure(nlTestSuite * apSuite, void * apContext)
2539+
{
2540+
TestContext & ctx = *static_cast<TestContext *>(apContext);
2541+
CHIP_ERROR err = CHIP_NO_ERROR;
2542+
2543+
Messaging::ReliableMessageMgr * rm = ctx.GetExchangeManager().GetReliableMessageMgr();
2544+
// Shouldn't have anything in the retransmit table when starting the test.
2545+
NL_TEST_ASSERT(apSuite, rm->TestGetCountRetransTable() == 0);
2546+
2547+
MockInteractionModelApp delegate;
2548+
auto * engine = chip::app::InteractionModelEngine::GetInstance();
2549+
err = engine->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable());
2550+
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
2551+
NL_TEST_ASSERT(apSuite, !delegate.mGotEventResponse);
2552+
2553+
chip::app::AttributePathParams attributePathParams[1];
2554+
attributePathParams[0].mEndpointId = Test::kMockEndpoint2;
2555+
attributePathParams[0].mClusterId = Test::MockClusterId(3);
2556+
attributePathParams[0].mAttributeId = Test::MockAttributeId(1);
2557+
2558+
ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice());
2559+
readPrepareParams.mpEventPathParamsList = nullptr;
2560+
readPrepareParams.mEventPathParamsListSize = 0;
2561+
readPrepareParams.mpAttributePathParamsList = attributePathParams;
2562+
readPrepareParams.mAttributePathParamsListSize = 1;
2563+
2564+
{
2565+
app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate,
2566+
chip::app::ReadClient::InteractionType::Read);
2567+
2568+
ctx.GetLoopback().mNumMessagesToAllowBeforeError = 1;
2569+
ctx.GetLoopback().mMessageSendError = CHIP_ERROR_INCORRECT_STATE;
2570+
err = readClient.SendRequest(readPrepareParams);
2571+
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
2572+
2573+
ctx.DrainAndServiceIO();
2574+
NL_TEST_ASSERT(apSuite, engine->GetReportingEngine().GetNumReportsInFlight() == 0);
2575+
NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 0);
2576+
2577+
ctx.GetLoopback().mNumMessagesToAllowBeforeError = 0;
2578+
ctx.GetLoopback().mMessageSendError = CHIP_NO_ERROR;
2579+
}
2580+
2581+
NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadClients() == 0);
2582+
engine->Shutdown();
2583+
NL_TEST_ASSERT(apSuite, ctx.GetExchangeManager().GetNumActiveExchanges() == 0);
2584+
}
2585+
25342586
void TestReadInteraction::TestSubscribeRoundtripChunkStatusReportTimeout(nlTestSuite * apSuite, void * apContext)
25352587
{
25362588
TestContext & ctx = *static_cast<TestContext *>(apContext);
@@ -4155,6 +4207,7 @@ const nlTest sTests[] =
41554207
NL_TEST_DEF("TestSubscribeRoundtripStatusReportTimeout", chip::app::TestReadInteraction::TestSubscribeRoundtripStatusReportTimeout),
41564208
NL_TEST_DEF("TestPostSubscribeRoundtripStatusReportTimeout", chip::app::TestReadInteraction::TestPostSubscribeRoundtripStatusReportTimeout),
41574209
NL_TEST_DEF("TestReadChunkingStatusReportTimeout", chip::app::TestReadInteraction::TestReadChunkingStatusReportTimeout),
4210+
NL_TEST_DEF("TestReadReportFailure", chip::app::TestReadInteraction::TestReadReportFailure),
41584211
NL_TEST_DEF("TestSubscribeRoundtripChunkStatusReportTimeout", chip::app::TestReadInteraction::TestSubscribeRoundtripChunkStatusReportTimeout),
41594212
NL_TEST_DEF("TestPostSubscribeRoundtripChunkStatusReportTimeout", chip::app::TestReadInteraction::TestPostSubscribeRoundtripChunkStatusReportTimeout),
41604213
NL_TEST_DEF("TestPostSubscribeRoundtripChunkReportTimeout", chip::app::TestReadInteraction::TestPostSubscribeRoundtripChunkReportTimeout),

src/transport/raw/tests/NetworkTestHelpers.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,16 @@ class LoopbackTransport : public Transport::Base
103103

104104
CHIP_ERROR SendMessage(const Transport::PeerAddress & address, System::PacketBufferHandle && msgBuf) override
105105
{
106-
ReturnErrorOnFailure(mMessageSendError);
106+
if (mNumMessagesToAllowBeforeError == 0)
107+
{
108+
ReturnErrorOnFailure(mMessageSendError);
109+
}
107110
mSentMessageCount++;
108111
bool dropMessage = false;
112+
if (mNumMessagesToAllowBeforeError > 0)
113+
{
114+
--mNumMessagesToAllowBeforeError;
115+
}
109116
if (mNumMessagesToAllowBeforeDropping > 0)
110117
{
111118
--mNumMessagesToAllowBeforeDropping;
@@ -141,6 +148,7 @@ class LoopbackTransport : public Transport::Base
141148
mDroppedMessageCount = 0;
142149
mSentMessageCount = 0;
143150
mNumMessagesToAllowBeforeDropping = 0;
151+
mNumMessagesToAllowBeforeError = 0;
144152
mMessageSendError = CHIP_NO_ERROR;
145153
}
146154

@@ -160,6 +168,7 @@ class LoopbackTransport : public Transport::Base
160168
uint32_t mDroppedMessageCount = 0;
161169
uint32_t mSentMessageCount = 0;
162170
uint32_t mNumMessagesToAllowBeforeDropping = 0;
171+
uint32_t mNumMessagesToAllowBeforeError = 0;
163172
CHIP_ERROR mMessageSendError = CHIP_NO_ERROR;
164173
LoopbackTransportDelegate * mDelegate = nullptr;
165174
};

0 commit comments

Comments
 (0)