Skip to content
New issue

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

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

Already on GitHub? # to your account

Create a repro for the migrations file lock issue #2334

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions Tests/Realm.Tests/Database/MigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,45 @@ public class MigrationTests : RealmInstanceTest
{
private const string FileToMigrate = "ForMigrationsToCopyAndMigrate.realm";

[Test]
public void AAAAAA_MigrationLocksFiles()
{
var config = (RealmConfiguration)RealmConfiguration.DefaultConfiguration;

using (var realm = GetRealm())
{
}

var config2 = config.ConfigWithPath(config.DatabasePath);
config2.SchemaVersion = 99;

// If the line below or line 49 is commented out, the file can be deleted as normal.
config2.MigrationCallback = (migration, oldSchemaVersion) => { };

using (var realm2 = GetRealm(config2))
{
// If you comment this out, the test will succeed, even with a migration callback
var people = realm2.All<Person>();
}

// Try to delete the Realm file - this is a copy of Realm.DeleteRealm
var fullpath = config2.DatabasePath;

var filesToDelete = new[] { string.Empty, ".log_a", ".log_b", ".log", ".lock", ".note" }
.Select(ext => fullpath + ext)
.Where(File.Exists);

foreach (var file in filesToDelete)
{
Assert.DoesNotThrow(() => File.Delete(file), $"Failed to delete {file}");
}

if (Directory.Exists($"{fullpath}.management"))
{
Assert.DoesNotThrow(() => Directory.Delete($"{fullpath}.management", recursive: true), "Failed to delete management dir.");
}
}

[Test]
public void TriggerMigrationBySchemaVersion()
{
Expand Down