1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Fix "wait for import" until step potentially finishing early

If not obvious, the issue with previous code is that it was checking for `IsAvailableLocally`, while the import is happening on a different thread, so that method could return `true` before the importing has finished and `ItemUpdated` event is called.
This commit is contained in:
Salman Ahmed 2021-02-02 16:54:40 +03:00
parent 1d8de2f718
commit 8e96ffd1e6

View File

@ -89,7 +89,7 @@ namespace osu.Game.Tests.Online
addAvailabilityCheckStep("state importing", BeatmapAvailability.Importing);
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
AddUntilStep("wait for import", () => beatmaps.IsAvailableLocally(testBeatmapSet));
AddUntilStep("wait for import", () => beatmaps.CurrentImportTask?.IsCompleted == true);
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
}
@ -127,8 +127,6 @@ namespace osu.Game.Tests.Online
private void addAvailabilityCheckStep(string description, Func<BeatmapAvailability> expected)
{
// In DownloadTrackingComposite, state changes are scheduled one frame later, wait one step.
AddWaitStep("wait for potential change", 1);
AddAssert(description, () => availablilityTracker.Availability.Value.Equals(expected.Invoke()));
}
@ -157,6 +155,8 @@ namespace osu.Game.Tests.Online
{
public TaskCompletionSource<bool> AllowImport = new TaskCompletionSource<bool>();
public Task<BeatmapSetInfo> CurrentImportTask { get; private set; }
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize)
=> new TestDownloadRequest(set);
@ -168,7 +168,7 @@ namespace osu.Game.Tests.Online
public override async Task<BeatmapSetInfo> Import(BeatmapSetInfo item, ArchiveReader archive = null, CancellationToken cancellationToken = default)
{
await AllowImport.Task;
return await base.Import(item, archive, cancellationToken);
return await (CurrentImportTask = base.Import(item, archive, cancellationToken));
}
}