mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 18:42:56 +08:00
Use TaskCompletionSource
for better awaiting
This commit is contained in:
parent
80f7db8db3
commit
172552d551
@ -47,6 +47,8 @@ namespace osu.Game.Tests.Online
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUp() => Schedule(() =>
|
||||||
{
|
{
|
||||||
|
beatmaps.AllowImport = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
testBeatmapFile = getTestBeatmapOsz();
|
testBeatmapFile = getTestBeatmapOsz();
|
||||||
|
|
||||||
testBeatmapInfo = new TestBeatmap(Ruleset.Value).BeatmapInfo;
|
testBeatmapInfo = new TestBeatmap(Ruleset.Value).BeatmapInfo;
|
||||||
@ -83,7 +85,7 @@ namespace osu.Game.Tests.Online
|
|||||||
AddStep("finish download", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).TriggerSuccess(testBeatmapFile));
|
AddStep("finish download", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).TriggerSuccess(testBeatmapFile));
|
||||||
addAvailabilityCheckStep("state importing", BeatmapAvailability.Importing);
|
addAvailabilityCheckStep("state importing", BeatmapAvailability.Importing);
|
||||||
|
|
||||||
AddStep("allow importing", () => beatmaps.AllowImport.Set());
|
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||||
AddUntilStep("wait for import", () => beatmaps.IsAvailableLocally(testBeatmapSet));
|
AddUntilStep("wait for import", () => beatmaps.IsAvailableLocally(testBeatmapSet));
|
||||||
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
||||||
}
|
}
|
||||||
@ -91,7 +93,7 @@ namespace osu.Game.Tests.Online
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestTrackerRespectsSoftDeleting()
|
public void TestTrackerRespectsSoftDeleting()
|
||||||
{
|
{
|
||||||
AddStep("allow importing", () => beatmaps.AllowImport.Set());
|
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||||
AddStep("import beatmap", () => beatmaps.Import(testBeatmapSet).Wait());
|
AddStep("import beatmap", () => beatmaps.Import(testBeatmapSet).Wait());
|
||||||
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
||||||
|
|
||||||
@ -105,7 +107,7 @@ namespace osu.Game.Tests.Online
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestTrackerRespectsChecksum()
|
public void TestTrackerRespectsChecksum()
|
||||||
{
|
{
|
||||||
AddStep("allow importing", () => beatmaps.AllowImport.Set());
|
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||||
|
|
||||||
BeatmapInfo wrongBeatmap = null;
|
BeatmapInfo wrongBeatmap = null;
|
||||||
|
|
||||||
@ -144,7 +146,7 @@ namespace osu.Game.Tests.Online
|
|||||||
|
|
||||||
private class TestBeatmapManager : BeatmapManager
|
private class TestBeatmapManager : BeatmapManager
|
||||||
{
|
{
|
||||||
public readonly ManualResetEventSlim AllowImport = new ManualResetEventSlim();
|
public TaskCompletionSource<bool> AllowImport = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize)
|
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize)
|
||||||
=> new TestDownloadRequest(set);
|
=> new TestDownloadRequest(set);
|
||||||
@ -156,9 +158,7 @@ namespace osu.Game.Tests.Online
|
|||||||
|
|
||||||
public override async Task<BeatmapSetInfo> Import(BeatmapSetInfo item, ArchiveReader archive = null, CancellationToken cancellationToken = default)
|
public override async Task<BeatmapSetInfo> Import(BeatmapSetInfo item, ArchiveReader archive = null, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
while (!AllowImport.IsSet)
|
await AllowImport.Task;
|
||||||
await Task.Delay(10, cancellationToken);
|
|
||||||
|
|
||||||
return await base.Import(item, archive, cancellationToken);
|
return await base.Import(item, archive, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user