Skip to content

Commit

Permalink
Remove bits of the IM tests that check for explicit number of messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjerryjohns committed Aug 8, 2022
1 parent 7ed9d64 commit 79d3447
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 74 deletions.
91 changes: 17 additions & 74 deletions src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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*/,
Expand Down Expand Up @@ -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*/);

Expand Down Expand Up @@ -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);
Expand All @@ -2738,20 +2742,15 @@ 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;
ctx.GetLoopback().mDroppedMessageCount = 0;
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));
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/controller/tests/data_model/TestRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 79d3447

Please sign in to comment.