Skip to content

Commit

Permalink
Fixed bug where chunked reports would fail on Synchronized report sch…
Browse files Browse the repository at this point in the history
…eduler and added tests for Syncrhonized report scheduler interaction
  • Loading branch information
lpbeliveau-silabs committed Nov 21, 2023
1 parent 9969d44 commit ecb73f9
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 213 deletions.
1 change: 1 addition & 0 deletions src/app/reporting/ReportScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
IsEngineRunScheduled()));
}

bool IsChunkedReport() const { return mReadHandler->IsChunkedReport(); }
bool IsEngineRunScheduled() const { return mFlags.Has(ReadHandlerNodeFlags::EngineRunScheduled); }
void SetEngineRunScheduled(bool aEngineRunScheduled)
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/reporting/ReportSchedulerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ReportSchedulerImpl : public ReportScheduler
void OnSubscriptionReportSent(ReadHandler * aReadHandler) final;
void OnReadHandlerDestroyed(ReadHandler * aReadHandler) override;

bool IsReportScheduled(ReadHandler * aReadHandler);
virtual bool IsReportScheduled(ReadHandler * aReadHandler);

void ReportTimerCallback() override;

Expand Down
5 changes: 3 additions & 2 deletions src/app/reporting/SynchronizedReportSchedulerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void SynchronizedReportSchedulerImpl::CancelReport()
}

/// @brief Checks if the timer is active for the ReportScheduler
bool SynchronizedReportSchedulerImpl::IsReportScheduled()
bool SynchronizedReportSchedulerImpl::IsReportScheduled(ReadHandler * ReadHandler)
{
return mTimerDelegate->IsTimerActive(this);
}
Expand Down Expand Up @@ -140,7 +140,7 @@ CHIP_ERROR SynchronizedReportSchedulerImpl::CalculateNextReportTimeout(Timeout &
bool reportableAtMin = false;

mNodesPool.ForEachActiveObject([&reportableNow, &reportableAtMin, this, now](ReadHandlerNode * node) {
if (!node->IsEngineRunScheduled())
if (!node->IsEngineRunScheduled() || node->IsChunkedReport())
{
if (node->IsReportableNow(now))
{
Expand Down Expand Up @@ -185,6 +185,7 @@ void SynchronizedReportSchedulerImpl::TimerFired()
InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun();

mNodesPool.ForEachActiveObject([now](ReadHandlerNode * node) {
node->SetEngineRunScheduled(true);
if (node->GetMinTimestamp() <= now)
{
node->SetCanBeSynced(true);
Expand Down
2 changes: 1 addition & 1 deletion src/app/reporting/SynchronizedReportSchedulerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SynchronizedReportSchedulerImpl : public ReportSchedulerImpl, public Timer

void OnTransitionToIdle() override;

bool IsReportScheduled();
bool IsReportScheduled(ReadHandler * ReadHandler) override;

void TimerFired() override;

Expand Down
4 changes: 2 additions & 2 deletions src/app/reporting/tests/MockReportScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace reporting {

static chip::app::DefaultTimerDelegate sTimerDelegate;
static ReportSchedulerImpl sTestDefaultReportScheduler(&sTimerDelegate);
static SynchronizedReportSchedulerImpl sTestReportScheduler(&sTimerDelegate);
static SynchronizedReportSchedulerImpl sTestSyncReportScheduler(&sTimerDelegate);

ReportSchedulerImpl * GetDefaultReportScheduler()
{
Expand All @@ -38,7 +38,7 @@ ReportSchedulerImpl * GetDefaultReportScheduler()

SynchronizedReportSchedulerImpl * GetSynchronizedReportScheduler()
{
return &sTestReportScheduler;
return &sTestSyncReportScheduler;
}

} // namespace reporting
Expand Down
501 changes: 295 additions & 206 deletions src/app/tests/TestReadInteraction.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/tests/TestReportScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class TestReportScheduler
NL_TEST_ASSERT(aSuite, syncScheduler.GetNumReadHandlers() == 2);

// Confirm that a report emission is scheduled
NL_TEST_ASSERT(aSuite, syncScheduler.IsReportScheduled());
NL_TEST_ASSERT(aSuite, syncScheduler.IsReportScheduled(readHandler1));

// Validates that the lowest max is selected as the common max timestamp
NL_TEST_ASSERT(aSuite, syncScheduler.mNextMaxTimestamp == node1->GetMaxTimestamp());
Expand Down

0 comments on commit ecb73f9

Please sign in to comment.