1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00

Add failure test case.

- Only show failure if request wasn't cancelled
This commit is contained in:
Unknown 2017-11-28 11:57:29 +05:30
parent ac1fb5118c
commit e832f163e7
2 changed files with 49 additions and 33 deletions

View File

@ -9,6 +9,7 @@ using osu.Game.Users;
using osu.Framework.Allocation;
using OpenTK;
using System.Linq;
using System.Net;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
@ -19,11 +20,11 @@ namespace osu.Game.Tests.Visual
{
private RulesetStore rulesets;
private readonly Leaderboard leaderboard;
private readonly FailableLeaderboard leaderboard;
public TestCaseLeaderboard()
{
Add(leaderboard = new Leaderboard
Add(leaderboard = new FailableLeaderboard
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
@ -33,8 +34,8 @@ namespace osu.Game.Tests.Visual
AddStep(@"New Scores", newScores);
AddStep(@"Empty Scores", () => leaderboard.Scores = Enumerable.Empty<Score>());
AddStep(@"Network failure", networkFailure);
AddStep(@"Real beatmap", realBeatmap);
newScores();
}
[BackgroundDependencyLoader]
@ -263,5 +264,21 @@ namespace osu.Game.Tests.Visual
},
};
}
private void networkFailure()
{
leaderboard.Beatmap = new BeatmapInfo();
}
private class FailableLeaderboard : Leaderboard
{
protected override void UpdateScores()
{
if (Beatmap?.OnlineBeatmapID == null)
OnUpdateFailed(new WebException());
else
base.UpdateScores();
}
}
}
}

View File

@ -21,7 +21,6 @@ using System.Linq;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Framework.Logging;
using System.Net;
using osu.Game.Rulesets;
using osu.Framework.Input;
using osu.Game.Beatmaps.ControlPoints;
@ -51,7 +50,6 @@ namespace osu.Game.Screens.Select.Leaderboards
set
{
scores = value;
getScoresRequest = null;
placeholderContainer.FadeOut(fade_duration);
scrollFlow?.FadeOut(fade_duration).Expire();
@ -120,7 +118,7 @@ namespace osu.Game.Screens.Select.Leaderboards
if (value == scope) return;
scope = value;
updateScores();
UpdateScores();
}
}
@ -171,7 +169,7 @@ namespace osu.Game.Screens.Select.Leaderboards
Scores = null;
pendingBeatmapSwitch?.Cancel();
pendingBeatmapSwitch = Schedule(updateScores);
pendingBeatmapSwitch = Schedule(UpdateScores);
}
}
@ -195,13 +193,14 @@ namespace osu.Game.Screens.Select.Leaderboards
private GetScoresRequest getScoresRequest;
private void handleRulesetChange(RulesetInfo ruleset) => updateScores();
private void handleRulesetChange(RulesetInfo ruleset) => UpdateScores();
private void updateScores()
protected virtual void UpdateScores()
{
if (!IsLoaded) return;
getScoresRequest?.Cancel();
getScoresRequest = null;
Scores = null;
@ -221,34 +220,34 @@ namespace osu.Game.Screens.Select.Leaderboards
{
Scores = r.Scores;
};
getScoresRequest.Failure += e =>
{
// TODO: check why failure is repeatedly invoked even on successful requests
if (e is WebException)
{
Scores = null;
placeholderFlow.Children = new Drawable[]
{
new RetryButton
{
Action = updateScores,
Margin = new MarginPadding { Right = 10 },
},
new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Text = @"Couldn't retrieve scores!",
TextSize = 22,
},
};
placeholderContainer.FadeIn(fade_duration);
Logger.Error(e, @"Couldn't fetch beatmap scores!");
}
};
getScoresRequest.Failure += OnUpdateFailed;
api.Queue(getScoresRequest);
}
protected void OnUpdateFailed(Exception e)
{
if (e is OperationCanceledException) return;
Scores = null;
placeholderFlow.Children = new Drawable[]
{
new RetryButton
{
Action = UpdateScores,
Margin = new MarginPadding { Right = 10 },
},
new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Text = @"Couldn't retrieve scores!",
TextSize = 22,
},
};
placeholderContainer.FadeIn(fade_duration);
Logger.Error(e, @"Couldn't fetch beatmap scores!");
}
protected override void Update()
{
base.Update();