1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:07:33 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCasePlayerReferenceLeaking.cs

57 lines
1.7 KiB
C#
Raw Normal View History

// 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.
using System;
using osu.Framework.Lists;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual
{
public class TestCasePlayerReferenceLeaking : AllPlayersTestCase
{
private readonly WeakList<WorkingBeatmap> workingWeakReferences = new WeakList<WorkingBeatmap>();
private readonly WeakList<Player> playerWeakReferences = new WeakList<Player>();
protected override void AddCheckSteps()
{
AddUntilStep(() =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
int count = 0;
workingWeakReferences.ForEachAlive(_ => count++);
return count == 1;
}, "no leaked beatmaps");
AddUntilStep(() =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
int count = 0;
playerWeakReferences.ForEachAlive(_ => count++);
return count == 1;
}, "no leaked players");
}
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, IFrameBasedClock clock)
{
var working = base.CreateWorkingBeatmap(beatmap, clock);
workingWeakReferences.Add(working);
return working;
}
protected override Player CreatePlayer(Ruleset ruleset)
{
var player = base.CreatePlayer(ruleset);
playerWeakReferences.Add(player);
return player;
}
}
}