mirror of
https://github.com/osukey/osukey.git
synced 2025-04-29 10:47:22 +09:00
Add test coverage ensuring ruleset ID is correct after bracket read
Historically, tournament client may have written incorrect `OnlineID` values. We wanted to use `ShortName` to re-fetch the ruleset. This test ensures this flow is working correctly.
This commit is contained in:
parent
bc4d6a3ace
commit
a7a7584d3e
@ -1,9 +1,13 @@
|
|||||||
// 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.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Tests;
|
using osu.Game.Tests;
|
||||||
@ -12,6 +16,45 @@ namespace osu.Game.Tournament.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
public class DataLoadTest : TournamentHostTest
|
public class DataLoadTest : TournamentHostTest
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestRulesetGetsValidOnlineID()
|
||||||
|
{
|
||||||
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var osu = new TestTournament(runOnLoadComplete: () =>
|
||||||
|
{
|
||||||
|
// ReSharper disable once AccessToDisposedClosure
|
||||||
|
var storage = host.Storage.GetStorageForDirectory(Path.Combine("tournaments", "default"));
|
||||||
|
|
||||||
|
using (var stream = storage.GetStream("bracket.json", FileAccess.Write, FileMode.Create))
|
||||||
|
using (var writer = new StreamWriter(stream))
|
||||||
|
{
|
||||||
|
writer.Write(@"{
|
||||||
|
""Ruleset"": {
|
||||||
|
""ShortName"": ""taiko"",
|
||||||
|
""OnlineID"": -1,
|
||||||
|
""Name"": ""osu!taiko"",
|
||||||
|
""InstantiationInfo"": ""osu.Game.Rulesets.OsuTaiko.TaikoRuleset, osu.Game.Rulesets.Taiko"",
|
||||||
|
""Available"": true
|
||||||
|
} }");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
LoadTournament(host, osu);
|
||||||
|
|
||||||
|
osu.BracketLoadTask.WaitSafely();
|
||||||
|
|
||||||
|
Assert.That(osu.Dependencies.Get<IBindable<RulesetInfo>>().Value.OnlineID, Is.EqualTo(1));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
host.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestUnavailableRuleset()
|
public void TestUnavailableRuleset()
|
||||||
{
|
{
|
||||||
@ -19,7 +62,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = new TestTournament();
|
var osu = new TestTournament(true);
|
||||||
|
|
||||||
LoadTournament(host, osu);
|
LoadTournament(host, osu);
|
||||||
var storage = osu.Dependencies.Get<Storage>();
|
var storage = osu.Dependencies.Get<Storage>();
|
||||||
@ -35,9 +78,22 @@ namespace osu.Game.Tournament.Tests.NonVisual
|
|||||||
|
|
||||||
public class TestTournament : TournamentGameBase
|
public class TestTournament : TournamentGameBase
|
||||||
{
|
{
|
||||||
|
private readonly bool resetRuleset;
|
||||||
|
private readonly Action runOnLoadComplete;
|
||||||
|
|
||||||
|
public new Task BracketLoadTask => base.BracketLoadTask;
|
||||||
|
|
||||||
|
public TestTournament(bool resetRuleset = false, Action runOnLoadComplete = null)
|
||||||
|
{
|
||||||
|
this.resetRuleset = resetRuleset;
|
||||||
|
this.runOnLoadComplete = runOnLoadComplete;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
|
runOnLoadComplete?.Invoke();
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
if (resetRuleset)
|
||||||
Ruleset.Value = new RulesetInfo(); // not available
|
Ruleset.Value = new RulesetInfo(); // not available
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,8 +64,6 @@ namespace osu.Game.Tournament
|
|||||||
Textures.AddStore(new TextureLoaderStore(new StorageBackedResourceStore(storage)));
|
Textures.AddStore(new TextureLoaderStore(new StorageBackedResourceStore(storage)));
|
||||||
|
|
||||||
dependencies.CacheAs(new StableInfo(storage));
|
dependencies.CacheAs(new StableInfo(storage));
|
||||||
|
|
||||||
Task.Run(readBracket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readBracket()
|
private void readBracket()
|
||||||
@ -290,6 +288,8 @@ namespace osu.Game.Tournament
|
|||||||
MenuCursorContainer.Cursor.Alpha = 0;
|
MenuCursorContainer.Cursor.Alpha = 0;
|
||||||
|
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
Task.Run(readBracket);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void SaveChanges()
|
protected virtual void SaveChanges()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user