Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate beatmap update flow to handle edge cases better #19378

Merged
merged 20 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ec477a3
Add basic coverage of current behaviour of beatmap reimport
peppy Jul 25, 2022
6a3e8e3
Centralise calls to reset online info of a `BeatmapInfo`
peppy Jul 25, 2022
b7f6413
Fix old version of beatmap potentially not being deleted during updat…
peppy Jul 25, 2022
912218e
Ensure scores are transferred after beatmap update if difficulty hash…
peppy Jul 25, 2022
e5ad074
Ensure previous version prior to update loses online info after marke…
peppy Jul 25, 2022
2363a3f
Persist `DateAdded` over beatmap updates
peppy Jul 25, 2022
2e14d87
Move implementation of updating a beatmap to `BeatmapImporter`
peppy Jul 25, 2022
92dd1bc
Add test coverage of actual update flow
peppy Jul 25, 2022
8a0c8f5
Fix some realm pieces not being cleaned up
peppy Jul 25, 2022
9c411c2
Fix test nullability assertions
peppy Jul 25, 2022
d41ac36
Fix scenario where import is expected to be empty
peppy Jul 25, 2022
7d8a78e
Move tests to own class
peppy Jul 26, 2022
8370ca9
Add `ImportAsUpdate` method to `IModelImporter` to avoid otehr changes
peppy Jul 26, 2022
9939866
Revert one more missed change
peppy Jul 26, 2022
846291d
Refactor new tests to not suck as much as the old importer tests
peppy Jul 26, 2022
4c22b55
Fix incorrect handling if an update is processed with no changes
peppy Jul 26, 2022
1221cb1
Add comprehensive test coverage of update scenarios
peppy Jul 26, 2022
ee694c1
Add test coverage of no online ID scenario
peppy Jul 26, 2022
7f75184
Merge branch 'master' into beatmap-update-test
peppy Jul 26, 2022
9173271
Fix new update pathway not actually being used
peppy Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion osu.Game.Tests/Database/BeatmapImporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,61 @@ public void TestImportThenDeleteThenImportOptimisedPath()
});
}

[Test]
Copy link
Member Author

@peppy peppy Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to put these in a separate file, but splitting out this test feels like it should be done as a separate pass. There's a lot of helper methods and reorganisation to be done.

Scratch that, I already managed to avoid using any dependencies while rewriting these.

public void TestImportThenReimportWithNewDifficulty()
{
RunTestWithRealmAsync(async (realm, storage) =>
{
var importer = new BeatmapImporter(storage, realm);
using var store = new RealmRulesetStore(realm, storage);

string? pathOriginal = TestResources.GetTestBeatmapForImport();

string pathMissingOneBeatmap = pathOriginal.Replace(".osz", "_missing_difficulty.osz");

string extractedFolder = $"{pathOriginal}_extracted";
Directory.CreateDirectory(extractedFolder);

try
{
using (var zip = ZipArchive.Open(pathOriginal))
zip.WriteToDirectory(extractedFolder);

// remove one difficulty before first import
new FileInfo(Directory.GetFiles(extractedFolder, "*.osu").First()).Delete();

using (var zip = ZipArchive.Create())
{
zip.AddAllFromDirectory(extractedFolder);
zip.SaveTo(pathMissingOneBeatmap, new ZipWriterOptions(CompressionType.Deflate));
}

var firstImport = await importer.Import(new ImportTask(pathMissingOneBeatmap));
Assert.That(firstImport, Is.Not.Null);

Assert.That(realm.Realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending), Has.Count.EqualTo(1));
Assert.That(realm.Realm.All<BeatmapSetInfo>().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(11));

// Second import matches first but contains one extra .osu file.
var secondImport = await importer.Import(new ImportTask(pathOriginal));
Assert.That(secondImport, Is.Not.Null);

Assert.That(realm.Realm.All<BeatmapInfo>(), Has.Count.EqualTo(23));
Assert.That(realm.Realm.All<BeatmapSetInfo>(), Has.Count.EqualTo(2));

Assert.That(realm.Realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending), Has.Count.EqualTo(1));
Assert.That(realm.Realm.All<BeatmapSetInfo>().First(s => !s.DeletePending).Beatmaps, Has.Count.EqualTo(12));

// check the newly "imported" beatmap is not the original.
Assert.That(firstImport?.ID, Is.Not.EqualTo(secondImport?.ID));
}
finally
{
Directory.Delete(extractedFolder, true);
}
});
}

[Test]
public void TestImportThenReimportAfterMissingFiles()
{
Expand Down Expand Up @@ -742,7 +797,7 @@ public void TestImportThenDeleteThenImportWithOnlineIDsMissing()
await realm.Realm.WriteAsync(() =>
{
foreach (var b in imported.Beatmaps)
b.OnlineID = -1;
b.ResetOnlineInfo();
});

deleteBeatmapSet(imported, realm.Realm);
Expand Down
Loading