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
         }
     }
 }
Ejemplo n.º 2
0
 public void Setup()
 {
     _clock = FrozenClock.FreezeUtcNow();
     _subject = new Metronome(_period, _clock);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 public MetronomeTests()
 {
     _clock = FrozenClock.FreezeUtcNow();
     _subject = new Metronome(_period, _clock);
 }