Skip to content

Commit

Permalink
[ReportScheduler] Renaming mTestNextReportTimestamp (project-chip#31137)
Browse files Browse the repository at this point in the history
* Renaming mTestNextReportTimestamp since we now use it outside of tests

* Updated member description in .h

* Update src/app/reporting/SynchronizedReportSchedulerImpl.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Restyled by clang-format

---------

Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored Dec 21, 2023
1 parent b7e3bc0 commit 711ca50
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/app/reporting/SynchronizedReportSchedulerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ void SynchronizedReportSchedulerImpl::OnTransitionToIdle()
{
Timestamp now = mTimerDelegate->GetCurrentMonotonicTimestamp();
uint32_t targetIdleInterval = static_cast<uint32_t>(ICD_SLEEP_TIME_JITTER_MS);
VerifyOrReturn(now >= mTestNextReportTimestamp);
if (((mTestNextReportTimestamp - now) < Seconds16(targetIdleInterval)) && (now > mNextMinTimestamp))
VerifyOrReturn(now >= mNextReportTimestamp);
if (((mNextReportTimestamp - now) < Seconds16(targetIdleInterval)) && (now > mNextMinTimestamp))
{
// If the next report is due in less than the idle mode interval and we are past the min interval, we can just send it now
CancelReport();
Expand All @@ -67,7 +67,7 @@ CHIP_ERROR SynchronizedReportSchedulerImpl::ScheduleReport(Timeout timeout, Read
return CHIP_NO_ERROR;
}
ReturnErrorOnFailure(mTimerDelegate->StartTimer(this, timeout));
mTestNextReportTimestamp = now + timeout;
mNextReportTimestamp = now + timeout;

return CHIP_NO_ERROR;
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/reporting/SynchronizedReportSchedulerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class SynchronizedReportSchedulerImpl : public ReportSchedulerImpl, public Timer
Timestamp mNextMaxTimestamp = Milliseconds64(0);
Timestamp mNextMinTimestamp = Milliseconds64(0);

// Timestamp of the next report to be scheduled, only used for testing
Timestamp mTestNextReportTimestamp = Milliseconds64(0);
// Timestamp of the next report to be scheduled, used by OnTransitionToIdle to determine whether we should emit a report before
// the device goes to idle mode
Timestamp mNextReportTimestamp = Milliseconds64(0);
};

} // namespace reporting
Expand Down
28 changes: 14 additions & 14 deletions src/app/tests/TestReportScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class TestReportScheduler
// Validates that the highest reportable min is selected as the common min interval (0 here)
NL_TEST_ASSERT(aSuite, syncScheduler.mNextMinTimestamp == node1->GetMinTimestamp());
// Validates that the next report emission is scheduled on the common max timestamp
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == syncScheduler.mNextMaxTimestamp);
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == syncScheduler.mNextMaxTimestamp);

// Simulate waiting for the max interval to expire (2s)
sTestTimerSynchronizedDelegate.IncrementMockTimestamp(System::Clock::Milliseconds64(2000));
Expand All @@ -515,7 +515,7 @@ class TestReportScheduler
// Validate that the max timestamp for both readhandlers got updated and that the next report emission is scheduled on
// the new max timestamp for readhandler1
NL_TEST_ASSERT(aSuite, node1->GetMaxTimestamp() > sTestTimerSynchronizedDelegate.GetCurrentMonotonicTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node1->GetMaxTimestamp());

// Confirm behavior when a read handler becomes dirty
readHandler2->ForceDirtyState();
Expand All @@ -530,7 +530,7 @@ class TestReportScheduler

// Confirm that the next report emission is scheduled on the min timestamp of readHandler2 (now) as it is the highest
// reportable
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node2->GetMinTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node2->GetMinTimestamp());
NL_TEST_ASSERT(aSuite, node1->CanBeSynced() == true);

// Simulate a report emission for readHandler1
Expand Down Expand Up @@ -570,7 +570,7 @@ class TestReportScheduler

// Validate next report scheduled on the max timestamp of readHandler1
NL_TEST_ASSERT(aSuite, node1->GetMaxTimestamp() > sTestTimerSynchronizedDelegate.GetCurrentMonotonicTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node1->GetMaxTimestamp());

// Simulate readHandler1 becoming dirty after less than 1 seconds, since it is reportable now, this will Schedule an Engine
// run immediately
Expand All @@ -586,7 +586,7 @@ class TestReportScheduler
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler2));

// The next report should be scheduler on the max timestamp of readHandler1
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node1->GetMaxTimestamp());

sTestTimerSynchronizedDelegate.IncrementMockTimestamp(System::Clock::Milliseconds64(2000));
// Confirm node 2 can now be synced since the scheduler timer has fired on the max timestamp of readHandler1
Expand All @@ -598,7 +598,7 @@ class TestReportScheduler
readHandler2->mObserver->OnSubscriptionReportSent(readHandler2);
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler1));
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler2));
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node1->GetMaxTimestamp());

// Simulate a new ReadHandler being added with a min timestamp that will force a conflict

Expand All @@ -615,7 +615,7 @@ class TestReportScheduler

// Since the min interval on readHandler3 is 2, it should be above the current max timestamp, therefore the next report
// should still happen on the max timestamp of readHandler1 and the sync should be done on future reports
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node1->GetMaxTimestamp());
// The min timestamp should also not have changed since the min of readhandler3 is higher than the current max
NL_TEST_ASSERT(aSuite, syncScheduler.mNextMinTimestamp == node2->GetMinTimestamp());

Expand All @@ -635,7 +635,7 @@ class TestReportScheduler
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler2));

// Confirm that next report is scheduled on the max timestamp of readHandler3 and other 2 readHandlers are synced
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node3->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node3->GetMaxTimestamp());

sTestTimerSynchronizedDelegate.IncrementMockTimestamp(System::Clock::Milliseconds64(2000));
// Confirm nodes 1 and 2 can now be synced since the scheduler timer has fired on the max timestamp of readHandler1
Expand All @@ -655,7 +655,7 @@ class TestReportScheduler
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler1));
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler2));
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler3));
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node1->GetMaxTimestamp());

// Now simulate a new readHandler being added with a max forcing a conflict
ReadHandler * readHandler4 =
Expand All @@ -667,7 +667,7 @@ class TestReportScheduler
NL_TEST_ASSERT(aSuite, syncScheduler.GetNumReadHandlers() == 4);

// Confirm next report is scheduled on the max timestamp of readHandler4
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node4->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node4->GetMaxTimestamp());

sTestTimerSynchronizedDelegate.IncrementMockTimestamp(System::Clock::Milliseconds64(1100));
// Confirm node 1 and 2 can now be synced since the scheduler timer has fired on the max timestamp of readHandler4
Expand Down Expand Up @@ -714,7 +714,7 @@ class TestReportScheduler
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler4));

// Next emission should be scheduled on the max timestamp of readHandler4 as it is the most restrictive
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node4->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node4->GetMaxTimestamp());

sTestTimerSynchronizedDelegate.IncrementMockTimestamp(System::Clock::Milliseconds64(1000));
// Confirm node 1 and 2 can now be synced since the scheduler timer has fired on the max timestamp of readHandler4
Expand Down Expand Up @@ -761,7 +761,7 @@ class TestReportScheduler
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler2));

// Confirm next report is scheduled on the max timestamp of readHandler1 and readhandler2 is not synced
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node1->GetMaxTimestamp());
// Node 2's sync timestamp should have remained unaffected since its min is higher
NL_TEST_ASSERT(aSuite, node2->CanBeSynced() == false);

Expand All @@ -775,7 +775,7 @@ class TestReportScheduler
syncScheduler.OnSubscriptionReportSent(readHandler1);
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler1));
NL_TEST_ASSERT(aSuite, !syncScheduler.IsReportableNow(readHandler2));
NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node2->GetMinTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node2->GetMinTimestamp());

sTestTimerSynchronizedDelegate.IncrementMockTimestamp(System::Clock::Milliseconds64(1000));
NL_TEST_ASSERT(aSuite, node1->CanBeSynced() == true);
Expand All @@ -786,7 +786,7 @@ class TestReportScheduler
syncScheduler.OnSubscriptionReportSent(readHandler1);
syncScheduler.OnSubscriptionReportSent(readHandler2);

NL_TEST_ASSERT(aSuite, syncScheduler.mTestNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, syncScheduler.mNextReportTimestamp == node1->GetMaxTimestamp());
NL_TEST_ASSERT(aSuite, node2->CanBeSynced() == false);

syncScheduler.UnregisterAllHandlers();
Expand Down

0 comments on commit 711ca50

Please sign in to comment.