private async Task MonitorServerAsync()
 {
     var metronome = new Metronome(_interval);
     var heartbeatCancellationToken = _cancellationTokenSource.Token;
     while (!heartbeatCancellationToken.IsCancellationRequested)
     {
         try
         {
             await HeartbeatAsync(heartbeatCancellationToken).ConfigureAwait(false);
             var newHeartbeatDelay = new HeartbeatDelay(metronome.GetNextTickDelay(), __minHeartbeatInterval);
             var oldHeartbeatDelay = Interlocked.Exchange(ref _heartbeatDelay, newHeartbeatDelay);
             if (oldHeartbeatDelay != null)
             {
                 oldHeartbeatDelay.Dispose();
             }
             await newHeartbeatDelay.Task.ConfigureAwait(false);
         }
         catch
         {
             // ignore these exceptions
         }
     }
 }
 public void Setup()
 {
     _clock = FrozenClock.FreezeUtcNow();
     _subject = new Metronome(_period, _clock);
 }
 public void GetNextTickDelay_should_be_infinite_if_period_is_infinite()
 {
     var period = Timeout.InfiniteTimeSpan;
     var subject = new Metronome(period);
     subject.GetNextTickDelay().Should().Be(Timeout.InfiniteTimeSpan);
 }
Beispiel #4
0
 public MetronomeTests()
 {
     _clock = FrozenClock.FreezeUtcNow();
     _subject = new Metronome(_period, _clock);
 }