using Xunit;

namespace ZB.MOM.WW.ScadaBridge.IntegrationTests.Cluster;

public class TwoNodeClusterFixtureTests
{
    [Fact]
    public async Task Fixture_FormsTwoNodeCluster_NodeAIsOldest()
    {
        await using var cluster = await TwoNodeClusterFixture.StartAsync();
        var a = Akka.Cluster.Cluster.Get(cluster.NodeA);
        var b = Akka.Cluster.Cluster.Get(cluster.NodeB);
        Assert.Equal(2, a.State.Members.Count);
        Assert.Equal(2, b.State.Members.Count);
        // NodeA started first => oldest (the singleton host).
        Assert.True(a.SelfMember.IsOlderThan(b.State.Members.First(m => m.Address == b.SelfAddress)));
    }
}
