1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 21:12:55 +08:00

Refactor beatmap importer tests to ensure realm is refreshed when waiting on state

This commit is contained in:
Dean Herbert 2021-11-30 14:12:49 +09:00
parent 6e4cd91b7b
commit 0feec09966

View File

@ -852,7 +852,11 @@ namespace osu.Game.Tests.Database
{ {
IQueryable<RealmBeatmapSet>? resultSets = null; IQueryable<RealmBeatmapSet>? resultSets = null;
waitForOrAssert(() => (resultSets = realm.All<RealmBeatmapSet>().Where(s => !s.DeletePending && s.OnlineID == 241526)).Any(), waitForOrAssert(() =>
{
realm.Refresh();
return (resultSets = realm.All<RealmBeatmapSet>().Where(s => !s.DeletePending && s.OnlineID == 241526)).Any();
},
@"BeatmapSet did not import to the database in allocated time.", timeout); @"BeatmapSet did not import to the database in allocated time.", timeout);
// ensure we were stored to beatmap database backing... // ensure we were stored to beatmap database backing...
@ -865,16 +869,16 @@ namespace osu.Game.Tests.Database
// ReSharper disable once PossibleUnintendedReferenceComparison // ReSharper disable once PossibleUnintendedReferenceComparison
IEnumerable<RealmBeatmap> queryBeatmaps() => realm.All<RealmBeatmap>().Where(s => s.BeatmapSet != null && s.BeatmapSet == set); IEnumerable<RealmBeatmap> queryBeatmaps() => realm.All<RealmBeatmap>().Where(s => s.BeatmapSet != null && s.BeatmapSet == set);
waitForOrAssert(() => queryBeatmaps().Count() == 12, @"Beatmaps did not import to the database in allocated time", timeout); Assert.AreEqual(12, queryBeatmaps().Count(), @"Beatmap count was not correct");
waitForOrAssert(() => queryBeatmapSets().Count() == 1, @"BeatmapSet did not import to the database in allocated time", timeout); Assert.AreEqual(1, queryBeatmapSets().Count(), @"Beatmapset count was not correct");
int countBeatmapSetBeatmaps = 0; int countBeatmapSetBeatmaps;
int countBeatmaps = 0; int countBeatmaps;
waitForOrAssert(() => Assert.AreEqual(
(countBeatmapSetBeatmaps = queryBeatmapSets().First().Beatmaps.Count) == countBeatmapSetBeatmaps = queryBeatmapSets().First().Beatmaps.Count,
(countBeatmaps = queryBeatmaps().Count()), countBeatmaps = queryBeatmaps().Count(),
$@"Incorrect database beatmap count post-import ({countBeatmaps} but should be {countBeatmapSetBeatmaps}).", timeout); $@"Incorrect database beatmap count post-import ({countBeatmaps} but should be {countBeatmapSetBeatmaps}).");
foreach (RealmBeatmap b in set.Beatmaps) foreach (RealmBeatmap b in set.Beatmaps)
Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineID == b.OnlineID)); Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineID == b.OnlineID));