/// <summary>
        /// Initializes and instance of the <see cref="TransportHeartbeat"/> class.
        /// </summary>
        /// <param name="serviceProvider">The <see cref="IDependencyResolver"/>.</param>
        public TransportHeartbeat(IOptions<SignalROptions> optionsAccessor,
                                  IPerformanceCounterManager counters,
                                  ILoggerFactory loggerFactory)
        {
            _transportOptions = optionsAccessor.Options.Transports;
            _counters = counters;
            _logger = loggerFactory.CreateLogger<TransportHeartbeat>();

            // REVIEW: When to dispose the timer?
            _timer = new Timer(Beat,
                               null,
                               _transportOptions.HeartbeatInterval(),
                               _transportOptions.HeartbeatInterval());
        }
        public void DefaultValues()
        {
            // Arrange
            var config = new TransportOptions();

            // Assert
            Assert.Equal(110, config.LongPolling.PollTimeout.TotalSeconds);
            Assert.Equal(30, config.DisconnectTimeout.TotalSeconds);
            Assert.Equal(10, config.KeepAlive.Value.TotalSeconds);
            Assert.Equal(20, config.KeepAliveTimeout().Value.TotalSeconds);
            Assert.Equal(5, config.HeartbeatInterval().TotalSeconds);
            Assert.Equal(100, config.TopicTtl().TotalSeconds);
        }
        public void HeartbeatIntervalIsASixthOfTheDisconnectTimeoutIfTheKeepAliveIsNull()
        {
            // Arrange
            var config = new TransportOptions();
            var random = new Random();
            config.DisconnectTimeout = TimeSpan.FromSeconds(random.Next(6, 31536000)); // 6 seconds to a year
            config.KeepAlive = null;

            // Assert
            Assert.Equal(TimeSpan.FromTicks(config.DisconnectTimeout.Ticks / 6), config.HeartbeatInterval());
        }
        public void HeartbeatIntervalIsHalfTheKeepAlive()
        {
            // Arrange
            var config = new TransportOptions();
            var random = new Random();
            config.KeepAlive = TimeSpan.FromSeconds(random.NextDouble() * 8 + 2); // 2 to 10 seconds

            // Assert
            Assert.Equal(TimeSpan.FromTicks(config.KeepAlive.Value.Ticks / 2), config.HeartbeatInterval());
        }