Esempio n. 1
0
        public void Given_Well_Formed_Alert_Behaviour_Two_Burst_Monitors_Unhealthy_Will_Not_Alert()
        {
            var ok = false;
            // Arrange
            var dic = new Dictionary <string, HealthReportEntry>();

            dic.Add("testhealthcheck", new HealthReportEntry(HealthStatus.Unhealthy, "", TimeSpan.Zero, null, null));

            var healthobserver = new Mock <IObserver <HealthReport> >();

            healthobserver.Setup(
                observer => observer.OnNext(It.IsAny <HealthReport>())).Callback(() => { ok = !ok; });

            var healthReportMock = new HealthReport(dic, TimeSpan.Zero);

            alertPublisher.Subscribe(healthobserver.Object);

            //Act
            alertPublisher.PublishAsync(healthReportMock, new CancellationToken());

            //Assert
            Assert.IsTrue(ok);

            //Act
            alertPublisher.PublishAsync(healthReportMock, new CancellationToken());

            //Assert
            Assert.IsTrue(ok);
        }
Esempio n. 2
0
        public void Given_Well_Formed_Alert_Behaviour_Will_Publish_All_Results_Even_Healthy()
        {
            // Arrange
            var ok = false;

            var httpendpointhealthcheck = new ServiceHealthCheck()
            {
                Name = "testhealthcheckalways",
                HealthCheckConditions = new HealthCheckConditions()
                {
                    HttpBehaviour = new HttpBehaviour()
                    {
                        HttpExpectedCode = 200,
                        HttpTimeoutMs    = 1000,
                        HttpVerb         = HttpVerb.Get
                    },
                },
                AlertBehaviour = new List <AlertBehaviour>()
                {
                    new AlertBehaviour()
                    {
                        AlertEvery = TimeSpan.FromSeconds(5),
                        AlertOnServiceRecovered = true,
                        TransportName           = "Dummy",
                        TransportMethod         = AlertTransportMethod.Email,
                        PublishAllResults       = true
                    }
                },
                EndpointOrHost     = "https://www.google.com",
                MonitoringInterval = TimeSpan.FromSeconds(1),
                ServiceType        = ServiceType.Http,
                Alert = true
            };

            var alertPublisher2 =
                new DictionaryPublisher(healthChecksBuilder, httpendpointhealthcheck, alertTransportSettings);


            var dic = new Dictionary <string, HealthReportEntry>();

            dic.Add("testhealthcheckalways", new HealthReportEntry(HealthStatus.Healthy, "", TimeSpan.Zero, null, null));

            var healthobserver = new Mock <IObserver <HealthReport> >();

            healthobserver.Setup(
                observer => observer.OnNext(It.IsAny <HealthReport>())).Callback(() =>
            {
                ok = !ok;
            });

            var healthReportMock = new HealthReport(dic, TimeSpan.Zero);

            alertPublisher2.Subscribe(healthobserver.Object);

            //Act
            alertPublisher2.PublishAsync(healthReportMock, new CancellationToken());

            //Assert
            Assert.IsTrue(ok);
        }
Esempio n. 3
0
        public void Unhealthy_Check_Count_Should_Reset_To_0_When_Healthy()
        {
            // Arrange
            var ok = true;

            var httpendpointhealthcheck = new ServiceHealthCheck()
            {
                Name = "testhealthcheckalways",
                HealthCheckConditions = new HealthCheckConditions()
                {
                    HttpBehaviour = new HttpBehaviour()
                    {
                        HttpExpectedCode = 200,
                        HttpVerb         = HttpVerb.Get
                    },
                },
                AlertBehaviour = new List <AlertBehaviour>()
                {
                    new AlertBehaviour()
                    {
                        AlertByFailCount        = 5,
                        AlertOnServiceRecovered = true,
                        TransportName           = "Dummy",
                        TransportMethod         = AlertTransportMethod.Email,
                        PublishAllResults       = false
                    }
                },
                EndpointOrHost     = "https://www.google.com",
                MonitoringInterval = TimeSpan.FromSeconds(1),
                ServiceType        = ServiceType.Http,
                Alert = true
            };

            var alertPublisher2 =
                new DictionaryPublisher(healthChecksBuilder, httpendpointhealthcheck, alertTransportSettings);


            var dic = new Dictionary <string, HealthReportEntry>();

            dic.Add("testhealthcheckalways", new HealthReportEntry(HealthStatus.Unhealthy, "", TimeSpan.Zero, null, null));

            var healthobserver = new Mock <IObserver <HealthReport> >();

            healthobserver.Setup(
                observer => observer.OnNext(It.IsAny <HealthReport>())).Callback(() =>
            {
                ok = !ok;
            });

            var healthReportMock = new HealthReport(dic, TimeSpan.Zero);

            alertPublisher2.Subscribe(healthobserver.Object);

            //Act
            alertPublisher2.PublishAsync(healthReportMock, new CancellationToken());

            //Assert
            Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 1);

            alertPublisher2.PublishAsync(healthReportMock, new CancellationToken());

            Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 2);

            alertPublisher2.PublishAsync(healthReportMock, new CancellationToken());

            Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 3);

            alertPublisher2.PublishAsync(healthReportMock, new CancellationToken());

            Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 4);

            dic.Clear();

            dic.Add("testhealthcheckalways", new HealthReportEntry(HealthStatus.Healthy, "", TimeSpan.Zero, null, null));

            alertPublisher2.PublishAsync(healthReportMock, new CancellationToken());

            Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 0);
        }