Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace ServiceControl.AcceptanceTests.Monitoring.CustomChecks
using AcceptanceTesting;
using AcceptanceTesting.EndpointTemplates;
using Contracts.CustomChecks;
using Infrastructure.DomainEvents;
using Microsoft.Extensions.DependencyInjection;
using NServiceBus;
using NServiceBus.AcceptanceTesting;
using NServiceBus.CustomChecks;
Expand All @@ -23,6 +25,8 @@ public async Task Should_come_back_while_the_check_is_still_failing()
CustomCheckView dismissed = null;
CustomCheckView returned = null;

CustomizeHostBuilder = hostBuilder => hostBuilder.Services.AddSingleton<IDomainHandler<ServiceControl.CustomChecks.CustomCheckDeleted>, DismissalObserver>();

await Define<Context>()
.WithEndpoint<Checked>()
.Do("Wait for the check to report a failure", async ctx =>
Expand All @@ -36,16 +40,13 @@ await Define<Context>()
})
.Do("Dismiss it from the page", async _ =>
await this.Delete($"/api/customchecks/{WithoutPrefix(dismissed.Id)}"))
.Do("Wait until it has gone", async _ =>
{
var checks = await this.TryGetMany<CustomCheckView>("/api/customchecks");

return checks.Items.All(check => check.CustomCheckId != CheckId);
})
.Do("Wait for the next report from the endpoint", async _ =>
.Do("Wait until the dismissal has been processed", ctx => Task.FromResult(ctx.DismissedAt != null))
// The endpoint reports every second, so the check is only ever absent for an instant and a
// poll cannot be expected to catch it. A report from after the dismissal proves the same thing.
.Do("Wait for a report from after the dismissal", async ctx =>
{
var checks = await this.TryGetMany<CustomCheckView>("/api/customchecks",
check => check.CustomCheckId == CheckId && check.Status == CheckStatus.Fail);
check => check.CustomCheckId == CheckId && check.Status == CheckStatus.Fail && check.ReportedAt > ctx.DismissedAt);

returned = checks.HasResult ? checks.Items.Single() : null;

Expand All @@ -67,6 +68,16 @@ static string WithoutPrefix(string id) =>
class Context : ScenarioContext, ISequenceContext
{
public int Step { get; set; }
public DateTime? DismissedAt { get; set; }
}

class DismissalObserver(Context context) : IDomainHandler<ServiceControl.CustomChecks.CustomCheckDeleted>
{
public Task Handle(ServiceControl.CustomChecks.CustomCheckDeleted domainEvent, CancellationToken cancellationToken = default)
{
context.DismissedAt = DateTime.UtcNow;
return Task.CompletedTask;
}
}

public class Checked : EndpointConfigurationBuilder
Expand Down
Loading