Batch changes: make window ranges exclusive to avoid infinite loop#62597
Conversation
There was a problem hiding this comment.
Struggling to put this in words that make sense, but the gist of what happened is:
schedule.ValidUntil()returns its end time- that end time can match (exactly) the end time of the active window
- whether a time is considered "in" a window is based on inclusive start and end times
- we detect that the end time of the window is "in" the window, even though there is zero time left in the window
- since there is zero time left, we make no progress that iteration (
schedule.total() == 0) - but since
schedule.ValidUntil()returns the same end time, we do not make it past the window that we are at the end at.
To solve this, I:
- made the end time of a window exclusive so we can not end up in a situation where we make zero progress and also do not progress the interval
- because this is a complex loop condition, I also added a failsafe which returns early if we make no progress
There was a problem hiding this comment.
This previously looped forever. Now it does not loop forever, and the non-nil check validates that we are not hitting the failsafe
There was a problem hiding this comment.
Becuase I was still uncomfortable with this loop, I added a fuzz test which I ran for ~10 minutes. It found no issues, but was able to surface the issues this PR fixes.
51b1937 to
e7f3615
Compare
peterguy
left a comment
There was a problem hiding this comment.
Ran some of my own tests using other time values. Ensured that each piece of the solution does what it's supposed to do. Looks good. It's a pretty complex algorithm, so there will probably be other issues with it.
BolajiOlajide
left a comment
There was a problem hiding this comment.
Nice. Thank you @camdencheek
This fixes an issue where we can potentially make no progress in the main loop of
Estimate. Commentary inline.Related Slack thread
Test plan
Added unit test for this case and fuzz test to search for other edge cases.