mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 19:52:55 +08:00
Add test for WorkingBeatmap leakage
This commit is contained in:
parent
f4cb0d7d8d
commit
14f5c814a6
@ -1,9 +1,12 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Lists;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
@ -43,6 +46,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
Player p = null;
|
Player p = null;
|
||||||
AddStep(ruleset.RulesetInfo.Name, () => p = loadPlayerFor(ruleset));
|
AddStep(ruleset.RulesetInfo.Name, () => p = loadPlayerFor(ruleset));
|
||||||
AddUntilStep(() => ContinueCondition(p));
|
AddUntilStep(() => ContinueCondition(p));
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -51,6 +55,20 @@ namespace osu.Game.Tests.Visual
|
|||||||
Player p = null;
|
Player p = null;
|
||||||
AddStep(r.Name, () => p = loadPlayerFor(r));
|
AddStep(r.Name, () => p = loadPlayerFor(r));
|
||||||
AddUntilStep(() => ContinueCondition(p));
|
AddUntilStep(() => ContinueCondition(p));
|
||||||
|
AddAssert("no leaked beatmaps", () =>
|
||||||
|
{
|
||||||
|
p = null;
|
||||||
|
|
||||||
|
GC.Collect();
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
workingWeakReferences.ForEachAlive(_ => count++);
|
||||||
|
|
||||||
|
Logger.Log($"reference count {count}");
|
||||||
|
|
||||||
|
return count == 1;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,21 +77,29 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
protected virtual IBeatmap CreateBeatmap(Ruleset ruleset) => new TestBeatmap(ruleset.RulesetInfo);
|
protected virtual IBeatmap CreateBeatmap(Ruleset ruleset) => new TestBeatmap(ruleset.RulesetInfo);
|
||||||
|
|
||||||
|
private readonly WeakList<WorkingBeatmap> workingWeakReferences = new WeakList<WorkingBeatmap>();
|
||||||
|
|
||||||
private Player loadPlayerFor(RulesetInfo ri) => loadPlayerFor(ri.CreateInstance());
|
private Player loadPlayerFor(RulesetInfo ri) => loadPlayerFor(ri.CreateInstance());
|
||||||
|
|
||||||
private Player loadPlayerFor(Ruleset r)
|
private Player loadPlayerFor(Ruleset r)
|
||||||
{
|
{
|
||||||
var beatmap = CreateBeatmap(r);
|
var beatmap = CreateBeatmap(r);
|
||||||
|
var working = new TestWorkingBeatmap(beatmap);
|
||||||
|
|
||||||
Beatmap.Value = new TestWorkingBeatmap(beatmap);
|
workingWeakReferences.Add(working);
|
||||||
|
|
||||||
|
Beatmap.Value = working;
|
||||||
Beatmap.Value.Mods.Value = new[] { r.GetAllMods().First(m => m is ModNoFail) };
|
Beatmap.Value.Mods.Value = new[] { r.GetAllMods().First(m => m is ModNoFail) };
|
||||||
|
|
||||||
if (Player != null)
|
Player?.Exit();
|
||||||
Remove(Player);
|
|
||||||
|
|
||||||
var player = CreatePlayer(r);
|
var player = CreatePlayer(r);
|
||||||
|
|
||||||
LoadComponentAsync(player, LoadScreen);
|
LoadComponentAsync(player, p =>
|
||||||
|
{
|
||||||
|
Player = p;
|
||||||
|
LoadScreen(p);
|
||||||
|
});
|
||||||
|
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user