Path: redb/redb.Tests.Integration/Tests/SqlitePro/SqliteProHashCanonHeaderCacheTests.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/SqlitePro/SqliteProHashCanonHeaderCacheTests.cs
----
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using redb.Core;
using redb.Core.Models.Entities;
using redb.Core.Pro.Extensions;
using redb.SQLite.Pro.Extensions;
using redb.Tests.Integration.Models;
namespace redb.Tests.Integration.Tests.SqlitePro;
///
/// The props cache serves an entry while its hash equals the stored one, and the hash covers the object header. Two
/// nodes (two cache domains on one database): node B changes the header so that the joined header canon stays the same
/// string ('|' inside a name); node A must not keep serving the old header from its cache.
///
public class SqliteProHashCanonHeaderCacheTests
{
private const string Cs = "Data Source=redb_tests_hashcanon_header_pro.db";
private static ServiceProvider Build(string domain)
{
var services = new ServiceCollection();
services.AddLogging(b => b.SetMinimumLevel(LogLevel.Warning));
services.AddRedbPro(options =>
{
options.UseSqlite(Cs);
options.Configure(c =>
{
c.EnablePropsCache = true;
c.SkipHashValidationOnCacheCheck = false;
c.CacheDomain = $"hash-canon-header-{domain}";
});
});
return services.BuildServiceProvider();
}
[Fact]
public async Task HeaderChangeWithTheSameJoinedCanon_IsSeenByAnotherNode()
{
Fixtures.SqliteTestSupport.DeleteDbFiles(Cs);
await using var nodeA = Build("a");
await using var nodeB = Build("b");
var a = nodeA.GetRequiredService();
var b = nodeB.GetRequiredService();
await a.InitializeAsync(ensureCreated: true);
await b.InitializeAsync();
await a.SyncSchemeAsync();
await b.SyncSchemeAsync();
var id = await a.SaveAsync(new RedbObject { name = "x|y", note = "", Props = new SimpleProps { Title = "p" } });
(await a.LoadAsync(id))!.name.Should().Be("x|y", "precondition: node A has the object in its cache");
var onB = (await b.LoadAsync(id))!;
onB.name = "x";
onB.note = "y|";
await b.SaveAsync(onB);
var onA = (await a.LoadAsync(id))!;
onA.name.Should().Be("x");
onA.note.Should().Be("y|");
}
}