From 79d3447c66e8d0eb6403372a18ad5d351804c4d7 Mon Sep 17 00:00:00 2001 From: Jerry Johns Date: Mon, 8 Aug 2022 12:12:09 -0700 Subject: [PATCH] Remove bits of the IM tests that check for explicit number of messages --- src/app/tests/TestReadInteraction.cpp | 91 ++++---------------- src/controller/tests/data_model/TestRead.cpp | 2 + 2 files changed, 19 insertions(+), 74 deletions(-) diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 11b976ff65c7c7..a8a855fb28f255 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -434,12 +434,14 @@ void TestReadInteraction::TestReadClient(nlTestSuite * apSuite, void * apContext // We don't actually want to deliver that message, because we want to // synthesize the read response. But we don't want it hanging around // forever either. - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.DrainAndServiceIO(); GenerateReportData(apSuite, apContext, buf, false /*aNeedInvalidReport*/, true /* aSuppressResponse*/); err = readClient.ProcessReportData(std::move(buf)); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + + ctx.GetLoopback().mNumMessagesToDrop = 0; } void TestReadInteraction::TestReadUnexpectedSubscriptionId(nlTestSuite * apSuite, void * apContext) @@ -458,8 +460,9 @@ void TestReadInteraction::TestReadUnexpectedSubscriptionId(nlTestSuite * apSuite // We don't actually want to deliver that message, because we want to // synthesize the read response. But we don't want it hanging around // forever either. - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.DrainAndServiceIO(); + ctx.GetLoopback().mNumMessagesToDrop = 0; // For read, we don't expect there is subscription id in report data. GenerateReportData(apSuite, apContext, buf, false /*aNeedInvalidReport*/, true /* aSuppressResponse*/, @@ -600,8 +603,9 @@ void TestReadInteraction::TestReadClientInvalidReport(nlTestSuite * apSuite, voi // We don't actually want to deliver that message, because we want to // synthesize the read response. But we don't want it hanging around // forever either. - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.DrainAndServiceIO(); + ctx.GetLoopback().mNumMessagesToDrop = 0; GenerateReportData(apSuite, apContext, buf, true /*aNeedInvalidReport*/, true /* aSuppressResponse*/); @@ -2718,7 +2722,7 @@ void TestReadInteraction::TestReadClientReceiveInvalidMessage(nlTestSuite * apSu chip::app::ReadClient::InteractionType::Read); ctx.GetLoopback().mSentMessageCount = 0; - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.GetLoopback().mNumMessagesToAllowBeforeDropping = 1; ctx.GetLoopback().mDroppedMessageCount = 0; err = readClient.SendRequest(readPrepareParams); @@ -2738,8 +2742,8 @@ void TestReadInteraction::TestReadClientReceiveInvalidMessage(nlTestSuite * apSu payloadHeader.SetMessageType(chip::Protocols::InteractionModel::MsgType::StatusResponse); rm->ClearRetransTable(readClient.mExchange.Get()); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mDroppedMessageCount == 1); + + printf("JJ: MSentMessage = %d\n", ctx.GetLoopback().mSentMessageCount); ctx.GetLoopback().mSentMessageCount = 0; ctx.GetLoopback().mNumMessagesToDrop = 0; ctx.GetLoopback().mNumMessagesToAllowBeforeDropping = 0; @@ -2747,11 +2751,6 @@ void TestReadInteraction::TestReadClientReceiveInvalidMessage(nlTestSuite * apSu readClient.OnMessageReceived(readClient.mExchange.Get(), payloadHeader, std::move(msgBuf)); ctx.DrainAndServiceIO(); - // TODO: Need to validate what status is being sent to the ReadHandler - // The ReadHandler closed its exchange when it sent the Report Data (which we dropped). - // Since we synthesized the StatusResponse to the ReadClient, instead of sending it from the ReadHandler, - // the only messages here are the ReadClient's StatusResponse to the unexpected message and an MRP ack. - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); NL_TEST_ASSERT(apSuite, delegate.mError == CHIP_IM_GLOBAL_STATUS(Busy)); } @@ -2800,7 +2799,7 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidStatusResponse(nlTest chip::app::ReadClient::InteractionType::Subscribe); ctx.GetLoopback().mSentMessageCount = 0; - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.GetLoopback().mNumMessagesToAllowBeforeDropping = 1; ctx.GetLoopback().mDroppedMessageCount = 0; err = readClient.SendRequest(readPrepareParams); @@ -2820,8 +2819,6 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidStatusResponse(nlTest payloadHeader.SetMessageType(chip::Protocols::InteractionModel::MsgType::StatusResponse); rm->ClearRetransTable(readClient.mExchange.Get()); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mDroppedMessageCount == 1); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); @@ -2834,13 +2831,6 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidStatusResponse(nlTest readClient.OnMessageReceived(readClient.mExchange.Get(), payloadHeader, std::move(msgBuf)); ctx.DrainAndServiceIO(); - // TODO: Need to validate what status is being sent to the ReadHandler - // The ReadHandler's exchange is closed when we synthesize the subscribe response, since it sent the - // Subscribe Response as the last message in the transaction. - // Since we synthesized the subscribe response to the ReadClient, instead of sending it from the ReadHandler, - // the only messages here are the ReadClient's StatusResponse to the unexpected message and an MRP ack. - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, delegate.mError == CHIP_IM_GLOBAL_STATUS(Busy)); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 0); } @@ -2890,7 +2880,7 @@ void TestReadInteraction::TestSubscribeClientReceiveWellFormedStatusResponse(nlT chip::app::ReadClient::InteractionType::Subscribe); ctx.GetLoopback().mSentMessageCount = 0; - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.GetLoopback().mNumMessagesToAllowBeforeDropping = 1; ctx.GetLoopback().mDroppedMessageCount = 0; err = readClient.SendRequest(readPrepareParams); @@ -2910,8 +2900,6 @@ void TestReadInteraction::TestSubscribeClientReceiveWellFormedStatusResponse(nlT payloadHeader.SetMessageType(chip::Protocols::InteractionModel::MsgType::StatusResponse); rm->ClearRetransTable(readClient.mExchange.Get()); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mDroppedMessageCount == 1); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); @@ -2924,13 +2912,6 @@ void TestReadInteraction::TestSubscribeClientReceiveWellFormedStatusResponse(nlT readClient.OnMessageReceived(readClient.mExchange.Get(), payloadHeader, std::move(msgBuf)); ctx.DrainAndServiceIO(); - // TODO: Need to validate what status is being sent to the ReadHandler - // The ReadHandler's exchange is still open when we synthesize the StatusResponse. - // Since we synthesized the StatusResponse to the ReadClient, instead of sending it from the ReadHandler, - // the only messages here are the ReadClient's StatusResponse to the unexpected message and an MRP ack. - // The ReadHandler should have sent a StatusResponse too, but it's buggy and does not do that. - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, delegate.mError == CHIP_ERROR_INVALID_MESSAGE_TYPE); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 0); } @@ -2980,7 +2961,7 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidReportMessage(nlTestS chip::app::ReadClient::InteractionType::Subscribe); ctx.GetLoopback().mSentMessageCount = 0; - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.GetLoopback().mNumMessagesToAllowBeforeDropping = 1; ctx.GetLoopback().mDroppedMessageCount = 0; err = readClient.SendRequest(readPrepareParams); @@ -2999,8 +2980,6 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidReportMessage(nlTestS payloadHeader.SetMessageType(chip::Protocols::InteractionModel::MsgType::ReportData); rm->ClearRetransTable(readClient.mExchange.Get()); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mDroppedMessageCount == 1); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); rm->ClearRetransTable(engine->ActiveHandlerAt(0)->mExchangeCtx.Get()); @@ -3013,13 +2992,6 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidReportMessage(nlTestS readClient.OnMessageReceived(readClient.mExchange.Get(), payloadHeader, std::move(msgBuf)); ctx.DrainAndServiceIO(); - // TODO: Need to validate what status is being sent to the ReadHandler - // The ReadHandler's exchange is still open when we synthesize the ReportData. - // Since we synthesized the ReportData to the ReadClient, instead of sending it from the ReadHandler, - // the only messages here are the ReadClient's StatusResponse to the unexpected message and an MRP ack. - // The ReadHandler should have sent a StatusResponse too, but it's buggy and does not do that. - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, delegate.mError == CHIP_ERROR_END_OF_TLV); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 0); @@ -3073,7 +3045,6 @@ void TestReadInteraction::TestSubscribeClientReceiveUnsolicitedInvalidReportMess err = readClient.SendRequest(readPrepareParams); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 5); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); delegate.mpReadHandler = engine->ActiveHandlerAt(0); @@ -3094,13 +3065,8 @@ void TestReadInteraction::TestSubscribeClientReceiveUnsolicitedInvalidReportMess Messaging::SendMessageFlags::kExpectResponse); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); - - // The server sends a data report. - // The client receives the data report data and sends out status report with invalid action. - // The server should respond with a status report of its own, leading to 4 messages (because - // the client would ack the server's status report), but it's buggy and just sends an ack to the status report it got. - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 3); } + NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadClients() == 0); engine->Shutdown(); } @@ -3143,7 +3109,7 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidSubscribeResponseMess chip::app::ReadClient::InteractionType::Subscribe); ctx.GetLoopback().mSentMessageCount = 0; - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.GetLoopback().mNumMessagesToAllowBeforeDropping = 3; ctx.GetLoopback().mDroppedMessageCount = 0; err = readClient.SendRequest(readPrepareParams); @@ -3165,8 +3131,6 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidSubscribeResponseMess payloadHeader.SetMessageType(chip::Protocols::InteractionModel::MsgType::SubscribeResponse); rm->ClearRetransTable(readClient.mExchange.Get()); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 4); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mDroppedMessageCount == 1); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); rm->ClearRetransTable(engine->ActiveHandlerAt(0)->mExchangeCtx.Get()); @@ -3179,12 +3143,6 @@ void TestReadInteraction::TestSubscribeClientReceiveInvalidSubscribeResponseMess readClient.OnMessageReceived(readClient.mExchange.Get(), payloadHeader, std::move(msgBuf)); ctx.DrainAndServiceIO(); - // TODO: Need to validate what status is being sent to the ReadHandler - // The ReadHandler's exchange is still open when we synthesize the subscribe response. - // Since we synthesized the subscribe response to the ReadClient, instead of sending it from the ReadHandler, - // the only messages here are the ReadClient's StatusResponse to the unexpected message and an MRP ack. - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, delegate.mError == CHIP_ERROR_INVALID_SUBSCRIPTION); } NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadClients() == 0); @@ -3237,7 +3195,6 @@ void TestReadInteraction::TestSubscribeClientReceiveUnsolicitedReportMessageWith err = readClient.SendRequest(readPrepareParams); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 5); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); delegate.mpReadHandler = engine->ActiveHandlerAt(0); @@ -3261,13 +3218,8 @@ void TestReadInteraction::TestSubscribeClientReceiveUnsolicitedReportMessageWith Messaging::SendMessageFlags::kExpectResponse); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); - - // The server sends a data report. - // The client receives the data report data and sends out status report with invalid subsciption. - // The server should respond with a status report of its own, leading to 4 messages (because - // the client would ack the server's status report), just sends an ack to the status report it got. - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 3); } + NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadClients() == 0); engine->Shutdown(); } @@ -3309,7 +3261,7 @@ void TestReadInteraction::TestReadChunkingInvalidSubscriptionId(nlTestSuite * ap chip::app::ReadClient::InteractionType::Subscribe); ctx.GetLoopback().mSentMessageCount = 0; - ctx.GetLoopback().mNumMessagesToDrop = 1; + ctx.GetLoopback().mNumMessagesToDrop = Test::LoopbackTransport::kUnlimitedMessageCount; ctx.GetLoopback().mNumMessagesToAllowBeforeDropping = 3; ctx.GetLoopback().mDroppedMessageCount = 0; err = readClient.SendRequest(readPrepareParams); @@ -3332,8 +3284,6 @@ void TestReadInteraction::TestReadChunkingInvalidSubscriptionId(nlTestSuite * ap NL_TEST_ASSERT(apSuite, writer.Finalize(&msgBuf) == CHIP_NO_ERROR); rm->ClearRetransTable(readClient.mExchange.Get()); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 4); - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mDroppedMessageCount == 1); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); @@ -3345,13 +3295,6 @@ void TestReadInteraction::TestReadChunkingInvalidSubscriptionId(nlTestSuite * ap readClient.OnMessageReceived(readClient.mExchange.Get(), payloadHeader, std::move(msgBuf)); ctx.DrainAndServiceIO(); - // TODO: Need to validate what status is being sent to the ReadHandler - // The ReadHandler's exchange is still open when we synthesize the report data message. - // Since we synthesized the second report data message to the ReadClient with invalid subscription id, instead of sending it - // from the ReadHandler, the only messages here are the ReadClient's StatusResponse to the unexpected message and an MRP - // ack. - NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); - NL_TEST_ASSERT(apSuite, delegate.mError == CHIP_ERROR_INVALID_SUBSCRIPTION); } NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadClients() == 0); diff --git a/src/controller/tests/data_model/TestRead.cpp b/src/controller/tests/data_model/TestRead.cpp index 569bc89ed98da7..680f9314753038 100644 --- a/src/controller/tests/data_model/TestRead.cpp +++ b/src/controller/tests/data_model/TestRead.cpp @@ -1646,6 +1646,8 @@ void TestReadInteraction::TestSubscribeAttributeTimeout(nlTestSuite * apSuite, v // ctx.GetIOContext().DriveIOUntil(System::Clock::Milliseconds32(1500), [&]() { return callback.mOnError >= 1; }); + ctx.GetLoopback().mNumMessagesToDrop = 0; + NL_TEST_ASSERT(apSuite, callback.mOnError == 1); NL_TEST_ASSERT(apSuite, callback.mLastError == CHIP_ERROR_TIMEOUT); NL_TEST_ASSERT(apSuite, callback.mOnDone == 1);