public async Task PublishAsync_WhenPartitionIsNotAvailable_ReturnsGracefully() { // Arrange. PublisherTestContext testContext = new PublisherTestContext(); // Act. await testContext.Publisher.PublishAsync(HealthReportBuilder.EmptyHealthReport, cancellationToken : default); // Assert. // If we are here, PublishAsync didn't explode. }
public async Task PublishAsync_ForStatelessServicePartition_ReportsInstanceHealth() { // Arrange. PublisherTestContext testContext = new PublisherTestContext(); testContext.ConfigureStatelessServicePartition(); // Act. await testContext.Publisher.PublishAsync(HealthReportBuilder.EmptyHealthReport, cancellationToken : default); // Assert. testContext.MockStatelessServicePartition !.Verify(partition => partition.ReportInstanceHealth(It.IsAny <SfHealthInformation>())); }
public async Task PublishAsync_WhenStatelessPartitionIsClosed_ReturnsGracefully() { // Arrange. PublisherTestContext testContext = new PublisherTestContext(); testContext.ConfigureStatelessServicePartition(closed: true); // Act. await testContext.Publisher.PublishAsync(HealthReportBuilder.EmptyHealthReport, cancellationToken : default); // Assert. // If we are here, PublishAsync didn't explode. }
public async Task PublishAsync_ForUnknownPartitionType_ThrowsArgumentException() { // Arrange. PublisherTestContext testContext = new PublisherTestContext(); testContext.ConfigureServicePartition(); // Act. async Task act() => await testContext.Publisher.PublishAsync(HealthReportBuilder.EmptyHealthReport, cancellationToken : default); // Assert. ArgumentException actualException = await Assert.ThrowsExceptionAsync <ArgumentException>(act); string partitionTypeName = testContext.MockServicePartition !.Object.GetType().ToString(); StringAssert.Contains(actualException.Message, partitionTypeName); }
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); }
public async Task PublishAsync_WhenCancellationIsRequested_ThrowsOperationCanceledException() { // Arrange. PublisherTestContext testContext = new PublisherTestContext(); testContext.ConfigureStatefulServicePartition(); CancellationTokenSource tokenSource = new CancellationTokenSource(); tokenSource.Cancel(); // Act. async Task act() => await testContext.Publisher.PublishAsync(HealthReportBuilder.EmptyHealthReport, tokenSource.Token); // Assert. await Assert.ThrowsExceptionAsync <OperationCanceledException>(act); }
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); }
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()); }
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()); }
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."); }