Skip to content

Commit

Permalink
fix(repeater): specify a default ping interval to 10s (#116)
Browse files Browse the repository at this point in the history
closes #115
  • Loading branch information
derevnjuk authored Dec 13, 2022
1 parent 82ade0c commit 57add9d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/SecTester.Repeater/Repeater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace SecTester.Repeater;

public class Repeater : IRepeater
{
private static readonly TimeSpan DefaultPingInterval = TimeSpan.FromSeconds(10);
private readonly EventBus _eventBus;
private readonly TimerProvider _heartbeat;
private readonly ILogger _logger;
Expand Down Expand Up @@ -72,6 +73,7 @@ private void SubscribeToEvents()
private async Task SchedulePing()
{
await SendStatus(RepeaterStatus.Connected).ConfigureAwait(false);
_heartbeat.Interval = DefaultPingInterval.TotalMilliseconds;
_heartbeat.Elapsed += async (_, _) => await SendStatus(RepeaterStatus.Connected).ConfigureAwait(false);
_heartbeat.Start();
}
Expand Down
1 change: 1 addition & 0 deletions test/SecTester.Repeater.Tests/RepeaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public async Task Start_SendsPingPeriodically()
await _sut.Start();

// assert
_timerProvider.Interval.Should().BeGreaterOrEqualTo(10_000);
_timerProvider.Elapsed += Raise.Event<ElapsedEventHandler>(new object(), elapsedEventArgs);
await _eventBus.Received(2).Publish(Arg.Is<RepeaterStatusEvent>(x => x.Status == RepeaterStatus.Connected && x.RepeaterId == Id));
}
Expand Down

0 comments on commit 57add9d

Please sign in to comment.