Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BUG] Regression 5.0.17 -> 5.0.18, Database.Rebuild() not disposing correctly #2549

Open
Blue101black opened this issue Sep 27, 2024 · 0 comments
Labels

Comments

@Blue101black
Copy link

Version
5.0.18

Describe the bug
The below unit test works in 5.0.17, but fails in 5.0.18.

I probably shouldn't be relying on Rebuild to dispose LiteDb and flush all pending writes to the stream, but our unit test does it this way and it breaks in 5.0.18 so I thought I would share.

Code to Reproduce

public class ReOpen_Tests
{
	[Fact]
	public void Should_Open()
	{
		byte[] databaseBytes;

		using (var stream = new MemoryStream())
		{
			var database = new LiteDatabase(stream);
			var collection = database.GetCollection<Item>();
			collection.Upsert(new Item(Guid.NewGuid()));
			var items = collection.Query().ToList();
			items.Should().HaveCount(1);

			database.Rebuild();
			databaseBytes = stream.ToArray();
		}
                
                // Opening the database with the existing stream should have the items still.
		using (var stream = new MemoryStream(databaseBytes))
		{
			var database = new LiteDatabase(stream);
			var items = database.GetCollection<Item>().Query().ToList();
			items.Should().HaveCount(1);
		}
	}

	private class Item
	{
		public Item(Guid id)
		{
			Id = id;
		}

		public Guid Id { get; set; }
	}
}

Expected behavior
The test above should pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant