48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
// Disable xUnit analyzer warning for async methods - cancellation token not relevant for these unit tests
|
|
#pragma warning disable xUnit1051
|
|
using Xunit;
|
|
|
|
namespace StellaOps.HybridLogicalClock.Tests;
|
|
|
|
public partial class HybridLogicalClockTests
|
|
{
|
|
[Fact]
|
|
public void Current_ReturnsCurrentState()
|
|
{
|
|
var timeProvider = new FakeTimeProvider();
|
|
var stateStore = new InMemoryHlcStateStore();
|
|
var clock = CreateClock(timeProvider, stateStore);
|
|
|
|
var ts = clock.Tick();
|
|
var current = clock.Current;
|
|
|
|
Assert.Equal(ts.PhysicalTime, current.PhysicalTime);
|
|
Assert.Equal(ts.LogicalCounter, current.LogicalCounter);
|
|
Assert.Equal(ts.NodeId, current.NodeId);
|
|
}
|
|
|
|
[Fact]
|
|
public void NodeId_ReturnsConfiguredNodeId()
|
|
{
|
|
var timeProvider = new FakeTimeProvider();
|
|
var stateStore = new InMemoryHlcStateStore();
|
|
var clock = CreateClock(timeProvider, stateStore);
|
|
|
|
Assert.Equal(TestNodeId, clock.NodeId);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Tick_PersistsStateAsync()
|
|
{
|
|
var timeProvider = new FakeTimeProvider();
|
|
var stateStore = new InMemoryHlcStateStore();
|
|
var clock = CreateClock(timeProvider, stateStore);
|
|
|
|
var ts = clock.Tick();
|
|
|
|
var persisted = await stateStore.LoadAsync(TestNodeId);
|
|
Assert.NotNull(persisted);
|
|
Assert.Equal(ts.PhysicalTime, persisted.Value.PhysicalTime);
|
|
}
|
|
}
|