Catch potential file access exceptions also in async flow

This commit is contained in:
Dean Herbert 2021-10-02 23:01:44 +09:00
parent 682fe5be78
commit 6ec2223b5c

View File

@ -39,25 +39,9 @@ namespace osu.Game.Tests.Database
realmFactory.Dispose(); realmFactory.Dispose();
try Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
{
Logger.Log($"Final database size: {testStorage.GetStream(realmFactory.Filename)?.Length ?? 0}");
}
catch
{
// windows runs may error due to file still being open.
}
realmFactory.Compact(); realmFactory.Compact();
Logger.Log($"Final database size after compact: {getFileSize(testStorage, realmFactory)}");
try
{
Logger.Log($"Final database size after compact: {testStorage.GetStream(realmFactory.Filename)?.Length ?? 0}");
}
catch
{
// windows runs may error due to file still being open.
}
} }
}); });
} }
@ -71,16 +55,28 @@ namespace osu.Game.Tests.Database
using (var realmFactory = new RealmContextFactory(testStorage, caller)) using (var realmFactory = new RealmContextFactory(testStorage, caller))
{ {
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}"); Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
await testAction(realmFactory, testStorage); await testAction(realmFactory, testStorage);
realmFactory.Dispose(); realmFactory.Dispose();
Logger.Log($"Final database size: {testStorage.GetStream(realmFactory.Filename)?.Length ?? 0}");
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
realmFactory.Compact(); realmFactory.Compact();
Logger.Log($"Final database size after compact: {testStorage.GetStream(realmFactory.Filename)?.Length ?? 0}"); Logger.Log($"Final database size after compact: {getFileSize(testStorage, realmFactory)}");
} }
}); });
} }
private static long getFileSize(Storage testStorage, RealmContextFactory realmFactory)
{
try
{
return testStorage.GetStream(realmFactory.Filename)?.Length ?? 0;
}
catch
{
// windows runs may error due to file still being open.
return 0;
}
}
} }
} }