From a8f80d76dd27862d2cabc27d21bf43da8fedfb41 Mon Sep 17 00:00:00 2001 From: Daniel Marbach Date: Thu, 7 Mar 2024 09:08:43 +0000 Subject: [PATCH] Address PushEnvelope TODOs (#3991) --- .../When_a_periodic_custom_check_fails.cs | 17 ++++++----- ...hen_reporting_custom_check_with_signalr.cs | 28 +++++++------------ .../When_a_message_has_failed.cs | 19 ++++++------- 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/src/ServiceControl.AcceptanceTests/Monitoring/CustomChecks/When_a_periodic_custom_check_fails.cs b/src/ServiceControl.AcceptanceTests/Monitoring/CustomChecks/When_a_periodic_custom_check_fails.cs index 19f4e6f448..e7546bd383 100644 --- a/src/ServiceControl.AcceptanceTests/Monitoring/CustomChecks/When_a_periodic_custom_check_fails.cs +++ b/src/ServiceControl.AcceptanceTests/Monitoring/CustomChecks/When_a_periodic_custom_check_fails.cs @@ -89,30 +89,29 @@ public SignalrStarter(MyContext context) .Build(); } - void ConnectionOnReceived(JsonElement jElement) + void EnvelopeReceived(JsonElement jElement) { var s = jElement.ToString(); - if (s.IndexOf("\"CustomCheckFailed\"") > 0) + if (s.IndexOf("\"CustomCheckFailed\"", StringComparison.Ordinal) <= 0) { - context.SignalrData = s; - context.SignalrEventReceived = true; + return; } + + context.SignalrData = s; + context.SignalrEventReceived = true; } protected override async Task OnStart(IMessageSession session, CancellationToken cancellationToken = default) { // We might also be able to strongly type this to match instead of just getting a string? - connection.On("PushEnvelope", ConnectionOnReceived); + connection.On("PushEnvelope", EnvelopeReceived); await connection.StartAsync(cancellationToken); context.SignalrStarted = connection.State == HubConnectionState.Connected; } - protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) - { - return connection.StopAsync(cancellationToken); - } + protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) => connection.StopAsync(cancellationToken); readonly MyContext context; readonly HubConnection connection; diff --git a/src/ServiceControl.AcceptanceTests/Monitoring/CustomChecks/When_reporting_custom_check_with_signalr.cs b/src/ServiceControl.AcceptanceTests/Monitoring/CustomChecks/When_reporting_custom_check_with_signalr.cs index 70cfb6e97d..dc9a8dbad8 100644 --- a/src/ServiceControl.AcceptanceTests/Monitoring/CustomChecks/When_reporting_custom_check_with_signalr.cs +++ b/src/ServiceControl.AcceptanceTests/Monitoring/CustomChecks/When_reporting_custom_check_with_signalr.cs @@ -42,10 +42,7 @@ public class MyContext : ScenarioContext public class EndpointThatUsesSignalR : EndpointConfigurationBuilder { - public EndpointThatUsesSignalR() - { - EndpointSetup(c => c.EnableFeature()); - } + public EndpointThatUsesSignalR() => EndpointSetup(c => c.EnableFeature()); class EnableSignalR : Feature { @@ -66,33 +63,28 @@ public SignalrStarter(MyContext context) .Build(); } - // TODO rename to better match what this is actually doing - void ConnectionOnReceived(JsonElement jElement) + void EnvelopeReceived(JsonElement jElement) { var s = jElement.ToString(); - if (s.IndexOf("\"EventLogItemAdded\"") > 0) + if (s.IndexOf("\"EventLogItemAdded\"", StringComparison.Ordinal) <= 0 || + s.IndexOf("EventLogItem/CustomChecks/CustomCheckFailed", StringComparison.Ordinal) <= 0) { - if (s.IndexOf("EventLogItem/CustomChecks/CustomCheckFailed") > 0) - { - context.SignalrData = s; - context.SignalrEventReceived = true; - } + return; } + + context.SignalrData = s; + context.SignalrEventReceived = true; } protected override Task OnStart(IMessageSession session, CancellationToken cancellationToken = default) { - // TODO Align this name with the one chosen for GlobalEventHandler // We might also be able to strongly type this to match instead of just getting a string? - connection.On("PushEnvelope", ConnectionOnReceived); + connection.On("PushEnvelope", EnvelopeReceived); return connection.StartAsync(cancellationToken); } - protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) - { - return connection.StopAsync(cancellationToken); - } + protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) => connection.StopAsync(cancellationToken); readonly MyContext context; readonly HubConnection connection; diff --git a/src/ServiceControl.AcceptanceTests/Recoverability/MessageFailures/When_a_message_has_failed.cs b/src/ServiceControl.AcceptanceTests/Recoverability/MessageFailures/When_a_message_has_failed.cs index ded843572c..f15b3c0035 100644 --- a/src/ServiceControl.AcceptanceTests/Recoverability/MessageFailures/When_a_message_has_failed.cs +++ b/src/ServiceControl.AcceptanceTests/Recoverability/MessageFailures/When_a_message_has_failed.cs @@ -300,29 +300,26 @@ public SignalRStarter(MyContext context) protected override async Task OnStart(IMessageSession session, CancellationToken cancellationToken = default) { - // TODO Align this name with the one chosen for GlobalEventHandler // We might also be able to strongly type this to match instead of just getting a string? - connection.On("PushEnvelope", ConnectionOnReceived); + connection.On("PushEnvelope", EnvelopeReceived); await connection.StartAsync(cancellationToken); await session.Send(new MyMessage(), cancellationToken); } - protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) - { - return connection.StopAsync(cancellationToken); - } + protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) => connection.StopAsync(cancellationToken); - // TODO rename to better match what this is actually doing - void ConnectionOnReceived(JsonElement jElement) + void EnvelopeReceived(JsonElement jElement) { var s = jElement.ToString(); - if (s.IndexOf("\"MessageFailuresUpdated\"") > 0) + if (s.IndexOf("\"MessageFailuresUpdated\"", StringComparison.Ordinal) <= 0) { - context.SignalrData = s; - context.SignalrEventReceived = true; + return; } + + context.SignalrData = s; + context.SignalrEventReceived = true; } readonly MyContext context;