Skip to content

Commit

Permalink
Add test to assert that the executionPlan query also releases the lock
Browse files Browse the repository at this point in the history
  • Loading branch information
JKamsker committed Jun 4, 2024
1 parent 1a9d6c6 commit 74e9ef1
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions LiteDB.Tests/Issues/Issue2471_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,52 @@ public void MultipleReadCleansUpTransaction()
collection.FindById(1);
}
}

#region Model

public class User
{
public int Id { get; set; }
public string Name { get; set; }
public int[] Phones { get; set; }
public List<Address> Addresses { get; set; }
}

public class Address
{
public string Street { get; set; }
}

#endregion Model

// Copied from IndexMultiKeyIndex, but this time we ensure that the lock is released by calling db.Checkpoint()
[Fact]
public void Ensure_Query_GetPlan_Releases_Lock()
{
using var db = new LiteDatabase(new MemoryStream());
var col = db.GetCollection<User>();

col.Insert(new User { Name = "John Doe", Phones = new int[] { 1, 3, 5 }, Addresses = new List<Address> { new Address { Street = "Av.1" }, new Address { Street = "Av.3" } } });
col.Insert(new User { Name = "Joana Mark", Phones = new int[] { 1, 4 }, Addresses = new List<Address> { new Address { Street = "Av.3" } } });

// create indexes
col.EnsureIndex(x => x.Phones);
col.EnsureIndex(x => x.Addresses.Select(z => z.Street));

// testing indexes expressions
var indexes = db.GetCollection("$indexes").FindAll().ToArray();

indexes[1]["expression"].AsString.Should().Be("$.Phones[*]");
indexes[2]["expression"].AsString.Should().Be("MAP($.Addresses[*]=>@.Street)");

// doing Phone query
var queryPhone = col.Query()
.Where(x => x.Phones.Contains(3));

var planPhone = queryPhone.GetPlan();

Action act = () => db.Checkpoint();

act.Should().NotThrow();
}
}

0 comments on commit 74e9ef1

Please sign in to comment.