mirror of
https://github.com/ppy/osu.git
synced 2025-01-22 18:53:22 +08:00
Refactor TestScenSpectatorPlayback
to properly clean up without async disposal
This commit is contained in:
parent
7a333ffdcc
commit
d58b85b381
@ -51,7 +51,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
private TestReplayRecorder recorder;
|
private TestReplayRecorder recorder;
|
||||||
|
|
||||||
private readonly ManualClock manualClock = new ManualClock();
|
private ManualClock manualClock;
|
||||||
|
|
||||||
private OsuSpriteText latencyDisplay;
|
private OsuSpriteText latencyDisplay;
|
||||||
|
|
||||||
@ -66,10 +66,17 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Cached]
|
[Cached]
|
||||||
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
|
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
|
||||||
|
|
||||||
[SetUp]
|
[SetUpSteps]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
|
AddStep("Reset recorder state", cleanUpState);
|
||||||
|
|
||||||
|
AddStep("Setup containers", () =>
|
||||||
{
|
{
|
||||||
replay = new Replay();
|
replay = new Replay();
|
||||||
|
manualClock = new ManualClock();
|
||||||
|
|
||||||
|
spectatorClient.OnNewFrames += onNewFrames;
|
||||||
|
|
||||||
users.BindTo(spectatorClient.PlayingUsers);
|
users.BindTo(spectatorClient.PlayingUsers);
|
||||||
users.BindCollectionChanged((obj, args) =>
|
users.BindCollectionChanged((obj, args) =>
|
||||||
@ -100,9 +107,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
spectatorClient.OnNewFrames += onNewFrames;
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
Add(new GridContainer
|
new GridContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Content = new[]
|
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)
|
private void onNewFrames(int userId, FrameDataBundle frames)
|
||||||
{
|
{
|
||||||
@ -189,6 +197,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestBasic()
|
public void TestBasic()
|
||||||
{
|
{
|
||||||
|
AddStep("Wait for user input", () => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
private double latency = SpectatorClient.TIME_BETWEEN_SENDS;
|
private double latency = SpectatorClient.TIME_BETWEEN_SENDS;
|
||||||
@ -232,11 +241,15 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[TearDownSteps]
|
[TearDownSteps]
|
||||||
public void TearDown()
|
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;
|
spectatorClient.OnNewFrames -= onNewFrames;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>
|
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>
|
||||||
|
Loading…
Reference in New Issue
Block a user