1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 07:02:54 +08:00

Refactor TestScenSpectatorPlayback to properly clean up without async disposal

This commit is contained in:
Dean Herbert 2021-12-06 16:35:06 +09:00
parent 7a333ffdcc
commit d58b85b381

View File

@ -51,7 +51,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private TestReplayRecorder recorder;
private readonly ManualClock manualClock = new ManualClock();
private ManualClock manualClock;
private OsuSpriteText latencyDisplay;
@ -66,10 +66,17 @@ namespace osu.Game.Tests.Visual.Gameplay
[Cached]
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
[SetUp]
public void SetUp() => Schedule(() =>
[SetUpSteps]
public void SetUpSteps()
{
AddStep("Reset recorder state", cleanUpState);
AddStep("Setup containers", () =>
{
replay = new Replay();
manualClock = new ManualClock();
spectatorClient.OnNewFrames += onNewFrames;
users.BindTo(spectatorClient.PlayingUsers);
users.BindCollectionChanged((obj, args) =>
@ -100,9 +107,9 @@ namespace osu.Game.Tests.Visual.Gameplay
}
}, true);
spectatorClient.OnNewFrames += onNewFrames;
Add(new GridContainer
Children = new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
@ -169,10 +176,11 @@ namespace osu.Game.Tests.Visual.Gameplay
}
}
}
},
latencyDisplay = new OsuSpriteText()
};
});
Add(latencyDisplay = new OsuSpriteText());
});
}
private void onNewFrames(int userId, FrameDataBundle frames)
{
@ -189,6 +197,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestBasic()
{
AddStep("Wait for user input", () => { });
}
private double latency = SpectatorClient.TIME_BETWEEN_SENDS;
@ -232,11 +241,15 @@ namespace osu.Game.Tests.Visual.Gameplay
[TearDownSteps]
public void TearDown()
{
AddStep("stop recorder", () =>
AddStep("stop recorder", cleanUpState);
}
private void cleanUpState()
{
recorder.Expire();
// Ensure previous recorder is disposed else it may affect the global playing state of `SpectatorClient`.
recorder?.RemoveAndDisposeImmediately();
recorder = null;
spectatorClient.OnNewFrames -= onNewFrames;
});
}
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>