Example #1
0
        protected override void InternalRun()
        {
            if (!ReplicationCheckGlobals.TcpListenerCheckHasRun)
            {
                ReplicationCheckGlobals.TcpListenerCheckHasRun = true;
            }
            else
            {
                ExTraceGlobals.HealthChecksTracer.TraceDebug((long)this.GetHashCode(), "TcpListenerCheck skipping because it has already been run once.");
                base.Skip();
            }
            if (!IgnoreTransientErrors.HasPassed(base.GetDefaultErrorKey(typeof(ReplayServiceCheck))))
            {
                ExTraceGlobals.HealthChecksTracer.TraceDebug <string>((long)this.GetHashCode(), "ReplayServiceCheck didn't pass! Skipping {0}.", base.Title);
                base.Skip();
            }
            if ((ReplicationCheckGlobals.ServerConfiguration & ServerConfig.Stopped) == ServerConfig.Stopped)
            {
                ExTraceGlobals.HealthChecksTracer.TraceDebug <string>((long)this.GetHashCode(), "Stopped server! Skipping {0}.", base.Title);
                base.Skip();
            }
            string text = null;
            bool   flag = TcpHealthCheck.TestHealth(base.ServerName, (int)this.replicationPort, 5000, out text);

            ExTraceGlobals.HealthChecksTracer.TraceDebug <string, bool, string>((long)this.GetHashCode(), "TcpListenerCheck: TestHealth() for server '{0}' returned: healthy={1}, errMsg='{2}'", base.ServerName, flag, text);
            if (!flag)
            {
                base.Fail(Strings.TcpListenerRequestFailed(base.ServerName, text));
            }
        }
        public async Task respect_configured_timeout_and_throw_operation_cancelled_exception()
        {
            var options = new TcpHealthCheckOptions();

            options.AddHost("invalid", 5555);

            var tcpHealthCheck = new TcpHealthCheck(options);

            var result = await tcpHealthCheck.CheckHealthAsync(new HealthCheckContext
            {
                Registration = new HealthCheckRegistration("tcp", instance: tcpHealthCheck, failureStatus: HealthStatus.Degraded,
                                                           null, timeout: null)
            }, new CancellationTokenSource(TimeSpan.FromSeconds(2)).Token);

            result.Exception.Should().BeOfType <OperationCanceledException>();
        }