Fix failing tests due to pooling safety changes

This commit is contained in:
Dean Herbert 2024-01-21 12:17:16 +09:00
parent a69fd8198d
commit 18d16018d3
No known key found for this signature in database
2 changed files with 42 additions and 45 deletions

View File

@ -1,10 +1,8 @@
// 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.Framework.Graphics;
using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
@ -16,37 +14,35 @@ public partial class TestSceneBarLine : ManiaSkinnableTestScene
[Test] [Test]
public void TestMinor() public void TestMinor()
{ {
AddStep("Create barlines", () => recreate()); AddStep("Create barlines", recreate);
} }
private void recreate(Func<IEnumerable<BarLine>>? createBarLines = null) private void recreate()
{ {
var stageDefinitions = new List<StageDefinition> var stageDefinitions = new List<StageDefinition>
{ {
new StageDefinition(4), new StageDefinition(4),
}; };
SetContents(_ => new ManiaPlayfield(stageDefinitions).With(s => SetContents(_ =>
{ {
if (createBarLines != null) var maniaPlayfield = new ManiaPlayfield(stageDefinitions);
// Must be scheduled so the pool is loaded before we try and retrieve from it.
Schedule(() =>
{ {
var barLines = createBarLines(); for (int i = 0; i < 64; i++)
foreach (var b in barLines)
s.Add(b);
return;
}
for (int i = 0; i < 64; i++)
{
s.Add(new BarLine
{ {
StartTime = Time.Current + i * 500, maniaPlayfield.Add(new BarLine
Major = i % 4 == 0, {
}); StartTime = Time.Current + i * 500,
} Major = i % 4 == 0,
})); });
}
});
return maniaPlayfield;
});
} }
} }
} }

View File

@ -25,16 +25,16 @@ public partial class TestSceneDrawableJudgement : OsuSkinnableTestScene
[Resolved] [Resolved]
private OsuConfigManager config { get; set; } = null!; private OsuConfigManager config { get; set; } = null!;
private readonly List<DrawablePool<TestDrawableOsuJudgement>> pools; private readonly List<DrawablePool<TestDrawableOsuJudgement>> pools = new List<DrawablePool<TestDrawableOsuJudgement>>();
public TestSceneDrawableJudgement() [TestCaseSource(nameof(validResults))]
public void Test(HitResult result)
{ {
pools = new List<DrawablePool<TestDrawableOsuJudgement>>(); showResult(result);
foreach (HitResult result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Skip(1))
showResult(result);
} }
private static IEnumerable<HitResult> validResults => Enum.GetValues<HitResult>().Skip(1);
[Test] [Test]
public void TestHitLightingDisabled() public void TestHitLightingDisabled()
{ {
@ -72,32 +72,33 @@ private void showResult(HitResult result)
pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1)); pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1));
else else
{ {
pool = pools[poolIndex];
// We need to make sure neither the pool nor the judgement get disposed when new content is set, and they both share the same parent. // We need to make sure neither the pool nor the judgement get disposed when new content is set, and they both share the same parent.
pool = pools[poolIndex];
((Container)pool.Parent!).Clear(false); ((Container)pool.Parent!).Clear(false);
} }
var container = new Container var container = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Child = pool,
{
pool,
pool.Get(j => j.Apply(new JudgementResult(new HitObject
{
StartTime = Time.Current
}, new Judgement())
{
Type = result,
}, null)).With(j =>
{
j.Anchor = Anchor.Centre;
j.Origin = Anchor.Centre;
})
}
}; };
// Must be scheduled so the pool is loaded before we try and retrieve from it.
Schedule(() =>
{
container.Add(pool.Get(j => j.Apply(new JudgementResult(new HitObject
{
StartTime = Time.Current
}, new Judgement())
{
Type = result,
}, null)).With(j =>
{
j.Anchor = Anchor.Centre;
j.Origin = Anchor.Centre;
}));
});
poolIndex++; poolIndex++;
return container; return container;
}); });