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.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI;
@ -16,37 +14,35 @@ public partial class TestSceneBarLine : ManiaSkinnableTestScene
[Test]
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>
{
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();
foreach (var b in barLines)
s.Add(b);
return;
}
for (int i = 0; i < 64; i++)
{
s.Add(new BarLine
for (int i = 0; i < 64; i++)
{
StartTime = Time.Current + i * 500,
Major = i % 4 == 0,
});
}
}));
maniaPlayfield.Add(new BarLine
{
StartTime = Time.Current + i * 500,
Major = i % 4 == 0,
});
}
});
return maniaPlayfield;
});
}
}
}

View File

@ -25,16 +25,16 @@ public partial class TestSceneDrawableJudgement : OsuSkinnableTestScene
[Resolved]
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>>();
foreach (HitResult result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Skip(1))
showResult(result);
showResult(result);
}
private static IEnumerable<HitResult> validResults => Enum.GetValues<HitResult>().Skip(1);
[Test]
public void TestHitLightingDisabled()
{
@ -72,32 +72,33 @@ private void showResult(HitResult result)
pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1));
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.
pool = pools[poolIndex];
((Container)pool.Parent!).Clear(false);
}
var container = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
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;
})
}
Child = pool,
};
// 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++;
return container;
});