1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 20:22:55 +08:00

Ensure tests cannot run forever

This commit is contained in:
Dean Herbert 2019-07-10 11:47:50 +09:00
parent 2a3601e43b
commit bd53a96507

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Replays; using osu.Game.Replays;
@ -160,10 +161,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestRewindInsideImportantSection() public void TestRewindInsideImportantSection()
{ {
// fast forward to important section fastForwardToPoint(3000);
while (handler.SetFrameFromTime(3000) != null)
{
}
setTime(4000, 4000); setTime(4000, 4000);
confirmCurrentFrame(4); confirmCurrentFrame(4);
@ -205,10 +203,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestRewindOutOfImportantSection() public void TestRewindOutOfImportantSection()
{ {
// fast forward to important section fastForwardToPoint(3500);
while (handler.SetFrameFromTime(3500) != null)
{
}
confirmCurrentFrame(3); confirmCurrentFrame(3);
confirmNextFrame(4); confirmNextFrame(4);
@ -227,6 +222,15 @@ namespace osu.Game.Tests.NonVisual
confirmNextFrame(2); confirmNextFrame(2);
} }
private void fastForwardToPoint(double destination)
{
for (int i = 0; i < 1000; i++)
if (handler.SetFrameFromTime(destination) == null)
return;
throw new TimeoutException("Seek was never fulfilled");
}
private void setTime(double set, double? expect) private void setTime(double set, double? expect)
{ {
Assert.AreEqual(expect, handler.SetFrameFromTime(set)); Assert.AreEqual(expect, handler.SetFrameFromTime(set));