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
1 changed files with 4 additions and 4 deletions

View File

@ -89,7 +89,7 @@ public void TestBeatmapDownloadingFlow()
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 @@ public void TestTrackerRespectsChecksum()
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 @@ private class TestBeatmapManager : BeatmapManager
{
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 @@ public TestBeatmapManager(Storage storage, IDatabaseContextFactory contextFactor
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));
}
}