Ejemplo n.º 1
0
        public async Task PublishAsync_ForHealthCheckWithValidHealthStatus_ReportsCorrectSfHealthState(string healthCheckName, HealthStatus healthCheckStatus, SfHealthState expectedSfHealthState)
        {
            // Arrange.
            PublisherTestContext testContext = new PublisherTestContext();

            testContext.ConfigureStatelessServicePartition();

            HealthReport report = new HealthReportBuilder()
                                  .AddEntry(healthCheckName, healthCheckStatus)
                                  .ToHealthReport();

            // Act.
            await testContext.Publisher.PublishAsync(report, cancellationToken : default);

            // Assert.
            Assert.AreEqual(expectedSfHealthState, testContext.ReportedSfHealthInformation(healthCheckName)?.HealthState);
        }
Ejemplo n.º 2
0
        public async Task PublishAsync_ForReportWithValidHealthStatus_ReportsCorrectSfHealthState(string healthCheckName, HealthStatus healthCheckStatus, SfHealthState expectedSfHealthState)
        {
            // Arrange.
            PublisherTestContext testContext = new PublisherTestContext();

            testContext.ConfigureStatefulServicePartition();

            // Currently report status is calculated as the worst of all healthchecks. In .NET 5 it will be possible to set it independently.
            HealthReport report = new HealthReportBuilder()
                                  .AddEntry(healthCheckName, healthCheckStatus)
                                  .ToHealthReport();

            // Act.
            await testContext.Publisher.PublishAsync(report, cancellationToken : default);

            // Assert.
            Assert.AreEqual(expectedSfHealthState, testContext.ReportedSfHealthInformation(ServiceFabricHealthCheckPublisher.HealthReportSummaryProperty)?.HealthState);
        }
Ejemplo n.º 3
0
        public async Task PublishAsync_ForHealthCheckWithInvalidHealthStatus_ThrowsArgumentException(string healthCheckName, HealthStatus invalidHealthCheckStatus)
        {
            // Arrange.
            PublisherTestContext testContext = new PublisherTestContext();

            testContext.ConfigureStatefulServicePartition();

            HealthReport report = new HealthReportBuilder()
                                  .AddEntry(healthCheckName, invalidHealthCheckStatus)
                                  .ToHealthReport();

            // Act.
            async Task act() => await testContext.Publisher.PublishAsync(report, cancellationToken : default);

            // Assert.
            ArgumentException actualException = await Assert.ThrowsExceptionAsync <ArgumentException>(act);

            StringAssert.Contains(actualException.Message, invalidHealthCheckStatus.ToString());
        }
Ejemplo n.º 4
0
        public async Task PublishAsync_ForReportWithInvalidHealthStatus_ThrowsArgumentException(string healthCheckName, HealthStatus invalidHealthCheckStatus)
        {
            // Arrange.
            PublisherTestContext testContext = new PublisherTestContext();

            testContext.ConfigureStatelessServicePartition();

            // Currently report status is calculated as the worst of all entries. In .NET 5 it will be possible to set it independently.
            HealthReport report = new HealthReportBuilder()
                                  .AddEntry(healthCheckName, invalidHealthCheckStatus)
                                  .ToHealthReport();

            // Act.
            async Task act() => await testContext.Publisher.PublishAsync(report, cancellationToken : default);

            // Assert.
            ArgumentException actualException = await Assert.ThrowsExceptionAsync <ArgumentException>(act);

            StringAssert.Contains(actualException.Message, invalidHealthCheckStatus.ToString());
        }
Ejemplo n.º 5
0
        public async Task PublishAsync_ForValidReportWithSeveralEntries_ReportsCorrectSfHealthInformation()
        {
            // Arrange.
            PublisherTestContext testContext = new PublisherTestContext();

            testContext.ConfigureStatelessServicePartition();

            string            healthyCheckName = "HealthyCheck";
            HealthReportEntry healthyEntry     = new HealthReportEntry(
                status: HealthStatus.Healthy,
                description: "Healthy entry description",
                duration: TimeSpan.FromMilliseconds(12639),
                exception: null,
                data: null);

            string            degradedCheckName = "DegradedCheck";
            HealthReportEntry degradedEntry     = new HealthReportEntry(
                status: HealthStatus.Degraded,
                description: "Degraded entry description",
                duration: TimeSpan.FromMilliseconds(111),
                exception: null,
                data: null);

            string            unhealthyCheckName = "UnhealthyCheck";
            HealthReportEntry unhealthyEntry     = new HealthReportEntry(
                status: HealthStatus.Unhealthy,
                description: "Unhealthy entry description",
                duration: TimeSpan.FromMilliseconds(73),
                exception: new InvalidOperationException("Unhealthy check performed invalid operation."),
                data: null);

            HealthReport report = new HealthReportBuilder()
                                  .AddEntry(healthyCheckName, healthyEntry)
                                  .AddEntry(degradedCheckName, degradedEntry)
                                  .AddEntry(unhealthyCheckName, unhealthyEntry)
                                  .SetTotalDuration(TimeSpan.FromSeconds(72))
                                  .ToHealthReport();

            // Act.
            await testContext.Publisher.PublishAsync(report, cancellationToken : default);

            // Assert.
            SfHealthInformation?healthyInfo = testContext.ReportedSfHealthInformation(healthyCheckName);

            NullableAssert.IsNotNull(healthyInfo);

            Assert.AreEqual(ServiceFabricHealthCheckPublisher.HealthReportSourceId, healthyInfo.SourceId, "SourceId from healthy check is incorrect.");
            Assert.AreEqual(healthyCheckName, healthyInfo.Property, "Property from healthy check is incorrect.");
            Assert.AreEqual(SfHealthState.Ok, healthyInfo.HealthState, "HealthState from healthy check is incorrect.");
            StringAssert.Contains(healthyInfo.Description, healthyEntry.Description, "Description from healthy check is not included.");
            StringAssert.Contains(healthyInfo.Description, healthyEntry.Duration.ToString(), "Duration from healthy check is not included.");

            SfHealthInformation?degradedInfo = testContext.ReportedSfHealthInformation(degradedCheckName);

            NullableAssert.IsNotNull(degradedInfo);

            Assert.AreEqual(ServiceFabricHealthCheckPublisher.HealthReportSourceId, degradedInfo.SourceId, "SourceId from degraded check is incorrect.");
            Assert.AreEqual(degradedCheckName, degradedInfo.Property, "Property from degraded check is incorrect.");
            Assert.AreEqual(SfHealthState.Warning, degradedInfo.HealthState, "HealthState from degraded check is incorrect.");
            StringAssert.Contains(degradedInfo.Description, degradedEntry.Description, "Description from degraded check is not included.");
            StringAssert.Contains(degradedInfo.Description, degradedEntry.Duration.ToString(), "Duration from degraded check is not included.");

            SfHealthInformation?unhealthyInfo = testContext.ReportedSfHealthInformation(unhealthyCheckName);

            NullableAssert.IsNotNull(unhealthyInfo);

            Assert.AreEqual(ServiceFabricHealthCheckPublisher.HealthReportSourceId, unhealthyInfo.SourceId, "SourceId from unhealthy check is incorrect.");
            Assert.AreEqual(unhealthyCheckName, unhealthyInfo.Property, "Property from unhealthy check is incorrect.");
            Assert.AreEqual(SfHealthState.Error, unhealthyInfo.HealthState, "HealthState from unhealthy check is incorrect.");
            StringAssert.Contains(unhealthyInfo.Description, unhealthyEntry.Description, "Description from unhealthy check is not included.");
            StringAssert.Contains(unhealthyInfo.Description, unhealthyEntry.Duration.ToString(), "Duration from unhealthy check is not included.");
            StringAssert.Contains(unhealthyInfo.Description, unhealthyEntry.Exception?.GetType().ToString(), "Exception from unhealthy check is not included.");

            SfHealthInformation?summaryInfo = testContext.ReportedSfHealthInformation(ServiceFabricHealthCheckPublisher.HealthReportSummaryProperty);

            NullableAssert.IsNotNull(summaryInfo);

            Assert.AreEqual(ServiceFabricHealthCheckPublisher.HealthReportSourceId, summaryInfo.SourceId, "SourceId from report is incorrect.");
            Assert.AreEqual(ServiceFabricHealthCheckPublisher.HealthReportSummaryProperty, summaryInfo.Property, "Property from report is incorrect.");
            Assert.AreEqual(SfHealthState.Error, summaryInfo.HealthState, "HealthState from report is incorrect.");
            StringAssert.Contains(summaryInfo.Description, report.TotalDuration.ToString(), "TotalDuration from report is not included.");
        }