Skip to content

Commit

Permalink
Fix #14776
Browse files Browse the repository at this point in the history
--SetResponseTimeout when it is subscribe or in chunked procedure
--Call OnReportConfirm in MoveToState when state is IsAwaitingReportResponsee

add missing test from PR ##15339

-- Add automatic test where initial chunked report has been received by read client during post-subscription, and exchange context and delegate has been passed from interaction model engine to read client, we expire the session so that the further chunked report cannot be receive by client so that onResponseTimeout is triggered from readClient.
  • Loading branch information
yunhanw-google committed Feb 19, 2022
1 parent e71be1c commit 3259572
Show file tree
Hide file tree
Showing 5 changed files with 545 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ ReadHandler::~ReadHandler()
{
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
}

InteractionModelEngine::GetInstance()->ReleaseClusterInfoList(mpAttributeClusterInfoList);
InteractionModelEngine::GetInstance()->ReleaseClusterInfoList(mpEventClusterInfoList);
InteractionModelEngine::GetInstance()->ReleaseClusterInfoList(mpDataVersionFilterList);
Expand Down Expand Up @@ -150,7 +149,6 @@ CHIP_ERROR ReadHandler::OnStatusResponse(Messaging::ExchangeContext * apExchange
case HandlerState::AwaitingReportResponse:
if (IsChunkedReport())
{
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
MoveToState(HandlerState::GeneratingReports);
if (mpExchangeCtx)
{
Expand All @@ -161,7 +159,6 @@ CHIP_ERROR ReadHandler::OnStatusResponse(Messaging::ExchangeContext * apExchange
}
else if (IsType(InteractionType::Subscribe))
{
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
if (IsPriming())
{
err = SendSubscribeResponse();
Expand Down Expand Up @@ -211,7 +208,6 @@ CHIP_ERROR ReadHandler::SendStatusReport(Protocols::InteractionModel::Status aSt
mpExchangeCtx = mpExchangeMgr->NewContext(mSessionHandle.Get(), this);
}
VerifyOrReturnLogError(mpExchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE);
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);

return StatusResponse::Send(aStatus, mpExchangeCtx,
/* aExpectResponse = */ false);
Expand All @@ -229,15 +225,16 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b
VerifyOrReturnLogError(mpExchangeCtx == nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnLogError(mSessionHandle, CHIP_ERROR_INCORRECT_STATE);
mpExchangeCtx = mpExchangeMgr->NewContext(mSessionHandle.Get(), this);
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);
}

VerifyOrReturnLogError(mpExchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE);
mIsChunkedReport = aMoreChunks;
bool noResponseExpected = IsType(InteractionType::Read) && !mIsChunkedReport;
if (!noResponseExpected)
{
MoveToState(HandlerState::AwaitingReportResponse);
}
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);
CHIP_ERROR err =
mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::ReportData, std::move(aPayload),
Messaging::SendFlags(noResponseExpected ? Messaging::SendMessageFlags::kNone
Expand Down Expand Up @@ -578,6 +575,11 @@ const char * ReadHandler::GetStateStr() const

void ReadHandler::MoveToState(const HandlerState aTargetState)
{
if (IsAwaitingReportResponse() && aTargetState != HandlerState::AwaitingReportResponse)
{
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
}

mState = aTargetState;
ChipLogDetail(DataManagement, "IM RH moving to [%s]", GetStateStr());
}
Expand Down Expand Up @@ -627,7 +629,6 @@ CHIP_ERROR ReadHandler::SendSubscribeResponse()

mIsPrimingReports = false;
MoveToState(HandlerState::GeneratingReports);

return mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::SubscribeResponse, std::move(packet));
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/StatusResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include <app/InteractionModelTimeout.h>
#include <app/MessageDef/StatusResponseMessage.h>
#include <app/StatusResponse.h>

Expand All @@ -36,6 +37,7 @@ CHIP_ERROR StatusResponse::Send(Protocols::InteractionModel::Status aStatus, Mes
response.Status(aStatus);
ReturnErrorOnFailure(response.GetError());
ReturnErrorOnFailure(writer.Finalize(&msgBuf));
apExchangeContext->SetResponseTimeout(kImMessageTimeout);
ReturnErrorOnFailure(apExchangeContext->SendMessage(Protocols::InteractionModel::MsgType::StatusResponse, std::move(msgBuf),
aExpectResponse ? Messaging::SendMessageFlags::kExpectResponse
: Messaging::SendMessageFlags::kNone));
Expand Down
1 change: 1 addition & 0 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ CHIP_ERROR WriteHandler::SendWriteResponse(System::PacketBufferTLVWriter && aMes
SuccessOrExit(err);

VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);
err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteResponse, std::move(packet),
mHasMoreChunks ? Messaging::SendMessageFlags::kExpectResponse
: Messaging::SendMessageFlags::kNone);
Expand Down
2 changes: 2 additions & 0 deletions src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class Engine
}
}

uint32_t GetNumReportsInFlight() { return mNumReportsInFlight; }

private:
friend class TestReportingEngine;
/**
Expand Down
Loading

0 comments on commit 3259572

Please sign in to comment.