using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Proxy.Supervisor;

namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Proxy.Tests;

[Trait("Category", "Unit")]
public sealed class HeartbeatMonitorTests
{
    [Fact]
    public void Single_miss_does_not_declare_dead()
    {
        var m = new HeartbeatMonitor();
        m.RecordMiss().ShouldBeFalse();
        m.RecordMiss().ShouldBeFalse();
    }

    [Fact]
    public void Three_consecutive_misses_declare_host_dead()
    {
        var m = new HeartbeatMonitor();
        m.RecordMiss().ShouldBeFalse();
        m.RecordMiss().ShouldBeFalse();
        m.RecordMiss().ShouldBeTrue();
    }

    [Fact]
    public void Ack_resets_the_miss_counter()
    {
        var m = new HeartbeatMonitor();
        m.RecordMiss();
        m.RecordMiss();

        m.RecordAck(DateTime.UtcNow);

        m.ConsecutiveMisses.ShouldBe(0);
        m.RecordMiss().ShouldBeFalse();
        m.RecordMiss().ShouldBeFalse();
    }
}
