mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 12:23:06 +08:00
Merge pull request #16595 from peppy/realm-block-timeout-assert-failure
Fix a failed `BlockAllOperations` leaving update realm in unretrieved state
This commit is contained in:
commit
1c6ad56821
@ -87,6 +87,11 @@ namespace osu.Game.Tests.Database
|
|||||||
|
|
||||||
hasThreadedUsage.Wait();
|
hasThreadedUsage.Wait();
|
||||||
|
|
||||||
|
// Usually the host would run the synchronization context work per frame.
|
||||||
|
// For the sake of keeping this test simple (there's only one update invocation),
|
||||||
|
// let's replace it so we can ensure work is run immediately.
|
||||||
|
SynchronizationContext.SetSynchronizationContext(new ImmediateExecuteSynchronizationContext());
|
||||||
|
|
||||||
Assert.Throws<TimeoutException>(() =>
|
Assert.Throws<TimeoutException>(() =>
|
||||||
{
|
{
|
||||||
using (realm.BlockAllOperations())
|
using (realm.BlockAllOperations())
|
||||||
@ -95,7 +100,17 @@ namespace osu.Game.Tests.Database
|
|||||||
});
|
});
|
||||||
|
|
||||||
stopThreadedUsage.Set();
|
stopThreadedUsage.Set();
|
||||||
|
|
||||||
|
// Ensure we can block a second time after the usage has ended.
|
||||||
|
using (realm.BlockAllOperations())
|
||||||
|
{
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ImmediateExecuteSynchronizationContext : SynchronizationContext
|
||||||
|
{
|
||||||
|
public override void Post(SendOrPostCallback d, object? state) => d(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -639,18 +639,19 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
realmRetrievalLock.Release();
|
restoreOperation();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new InvokeOnDisposal<RealmAccess>(this, factory =>
|
return new InvokeOnDisposal(restoreOperation);
|
||||||
{
|
|
||||||
factory.realmRetrievalLock.Release();
|
|
||||||
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
|
||||||
|
|
||||||
|
void restoreOperation()
|
||||||
|
{
|
||||||
|
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
||||||
|
realmRetrievalLock.Release();
|
||||||
// Post back to the update thread to revive any subscriptions.
|
// Post back to the update thread to revive any subscriptions.
|
||||||
syncContext?.Post(_ => ensureUpdateRealm(), null);
|
syncContext?.Post(_ => ensureUpdateRealm(), null);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/realm/realm-dotnet/blob/32f4ebcc88b3e80a3b254412665340cd9f3bd6b5/Realm/Realm/Extensions/ReflectionExtensions.cs#L46
|
// https://github.com/realm/realm-dotnet/blob/32f4ebcc88b3e80a3b254412665340cd9f3bd6b5/Realm/Realm/Extensions/ReflectionExtensions.cs#L46
|
||||||
|
Loading…
Reference in New Issue
Block a user