Skip to content

Commit

Permalink
Merge pull request #6011 from bdach/decoupling-framed-clock-test-tole…
Browse files Browse the repository at this point in the history
…rance

Increase tolerance in decoupling framed clock tests
  • Loading branch information
peppy authored Oct 2, 2023
2 parents 60fa441 + b89cd82 commit 49e1fbc
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions osu.Framework.Tests/Clocks/DecouplingFramedClockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public void TestBackwardPlaybackOverZeroBoundary()
while (source.IsRunning)
{
decouplingClock.ProcessFrame();
Assert.That(decouplingClock.CurrentTime, Is.EqualTo(source.CurrentTime).Within(5));
Assert.That(decouplingClock.CurrentTime, Is.EqualTo(source.CurrentTime).Within(30));
}

Assert.That(source.IsRunning, Is.False);
Expand Down Expand Up @@ -395,7 +395,7 @@ public void TestForwardPlaybackOverZeroBoundary()
decouplingClock.ProcessFrame();
}

Assert.That(source.CurrentTime, Is.EqualTo(decouplingClock.CurrentTime).Within(5));
Assert.That(source.CurrentTime, Is.EqualTo(decouplingClock.CurrentTime).Within(30));
Assert.That(source.IsRunning, Is.True);
}

Expand All @@ -416,11 +416,27 @@ public void TestForwardPlaybackOverLengthBoundary()
decouplingClock.ProcessFrame();

double time = decouplingClock.CurrentTime;
const double tolerance = 30;

while (decouplingClock.CurrentTime < 10000)
// The decoupling clock generally lags behind the source clock,
// so we don't want the threshold here to go up to the full tolerance,
// to avoid situations like so:
//
// x: decouplingClock
// o: sourceClock
//
// ------x-----------o------>
// 9980ms 10000ms
//
// The source clock has reached its playback limit and cannot seek further, so it will stop.
// The decoupling clock hasn't caught up to the source clock yet, but it is close enough to pass the tolerance check.
//
// Subtracting the tolerance ensures that both the decoupling and source clocks stay in the same 30ms band, but neither stops yet.
// We will assert that the source should eventually stop further down anyway.
while (decouplingClock.CurrentTime < 10000 - tolerance)
{
Assert.That(source.IsRunning, Is.True);
Assert.That(source.CurrentTime, Is.EqualTo(decouplingClock.CurrentTime).Within(5));
Assert.That(source.CurrentTime, Is.EqualTo(decouplingClock.CurrentTime).Within(30));
Assert.That(decouplingClock.CurrentTime, Is.GreaterThanOrEqualTo(time));
time = decouplingClock.CurrentTime;

Expand Down

0 comments on commit 49e1fbc

Please sign in to comment.