1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

Merge pull request #18871 from peppy/fix-realm-assertion-during-tests

Fix occasional failure in realm test proceedings due to incorrect `Debug.Assert`
This commit is contained in:
Dan Balasescu 2022-06-27 18:48:47 +09:00 committed by GitHub
commit 8f91ce8f0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,6 +102,12 @@ namespace osu.Game.Database
private Realm? updateRealm;
/// <summary>
/// Tracks whether a realm was ever fetched from this instance.
/// After a fetch occurs, blocking operations will be guaranteed to restore any subscriptions.
/// </summary>
private bool hasInitialisedOnce;
private bool isSendingNotificationResetEvents;
public Realm Realm => ensureUpdateRealm();
@ -121,6 +127,7 @@ namespace osu.Game.Database
if (updateRealm == null)
{
updateRealm = getRealmInstance();
hasInitialisedOnce = true;
Logger.Log(@$"Opened realm ""{updateRealm.Config.DatabasePath}"" at version {updateRealm.Config.SchemaVersion}");
@ -806,13 +813,7 @@ namespace osu.Game.Database
lock (realmLock)
{
if (updateRealm == null)
{
// null realm means the update thread has not yet retrieved its instance.
// we don't need to worry about reviving the update instance in this case, so don't bother with the SynchronizationContext.
Debug.Assert(!ThreadSafety.IsUpdateThread);
}
else
if (hasInitialisedOnce)
{
if (!ThreadSafety.IsUpdateThread)
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
@ -827,12 +828,12 @@ namespace osu.Game.Database
action.Value?.Dispose();
customSubscriptionsResetMap[action.Key] = null;
}
updateRealm?.Dispose();
updateRealm = null;
}
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
updateRealm?.Dispose();
updateRealm = null;
}
const int sleep_length = 200;