Phase 1 WP-11–22: Host infrastructure, Blazor Server UI, and integration tests
Host infrastructure (WP-11–17): - StartupValidator with 19 validation rules - /health/ready endpoint with DB + Akka health checks - Akka.NET bootstrap via AkkaHostedService (HOCON config, cluster, remoting, SBR) - Serilog with SiteId/NodeHostname/NodeRole enrichment - DeadLetterMonitorActor with count tracking - CoordinatedShutdown wiring (no Environment.Exit) - Windows Service support (UseWindowsService) Central UI (WP-18–21): - Blazor Server shell with Bootstrap 5, role-aware NavMenu - Login/logout flow (LDAP auth → JWT → HTTP-only cookie) - CookieAuthenticationStateProvider with idle timeout - LDAP group mapping CRUD page (Admin role) - Route guards with Authorize attributes per role - SignalR reconnection overlay for failover Integration tests (WP-22): - Startup validation, auth flow, audit transactions, readiness gating 186 tests pass (1 skipped: LDAP integration), zero warnings.
This commit is contained in:
74
tests/ScadaLink.Host.Tests/DeadLetterMonitorTests.cs
Normal file
74
tests/ScadaLink.Host.Tests/DeadLetterMonitorTests.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Akka.Actor;
|
||||
using Akka.Event;
|
||||
using Akka.TestKit.Xunit2;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using ScadaLink.Host.Actors;
|
||||
|
||||
namespace ScadaLink.Host.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// WP-15: Tests for DeadLetterMonitorActor.
|
||||
/// </summary>
|
||||
public class DeadLetterMonitorTests : TestKit
|
||||
{
|
||||
private readonly ILogger<DeadLetterMonitorActor> _logger =
|
||||
NullLoggerFactory.Instance.CreateLogger<DeadLetterMonitorActor>();
|
||||
|
||||
[Fact]
|
||||
public void DeadLetterMonitor_StartsWithZeroCount()
|
||||
{
|
||||
var monitor = Sys.ActorOf(Props.Create(() => new DeadLetterMonitorActor(_logger)));
|
||||
|
||||
monitor.Tell(GetDeadLetterCount.Instance);
|
||||
var response = ExpectMsg<DeadLetterCountResponse>();
|
||||
|
||||
Assert.Equal(0, response.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeadLetterMonitor_IncrementsOnDeadLetter()
|
||||
{
|
||||
var monitor = Sys.ActorOf(Props.Create(() => new DeadLetterMonitorActor(_logger)));
|
||||
|
||||
// Ensure actor has started and subscribed by sending a message and waiting for response
|
||||
monitor.Tell(GetDeadLetterCount.Instance);
|
||||
ExpectMsg<DeadLetterCountResponse>();
|
||||
|
||||
// Now publish dead letters — actor is guaranteed to be subscribed
|
||||
Sys.EventStream.Publish(new DeadLetter("test-message-1", Sys.DeadLetters, Sys.DeadLetters));
|
||||
Sys.EventStream.Publish(new DeadLetter("test-message-2", Sys.DeadLetters, Sys.DeadLetters));
|
||||
|
||||
// Use AwaitAssert to handle async event delivery
|
||||
AwaitAssert(() =>
|
||||
{
|
||||
monitor.Tell(GetDeadLetterCount.Instance);
|
||||
var response = ExpectMsg<DeadLetterCountResponse>();
|
||||
Assert.Equal(2, response.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeadLetterMonitor_CountAccumulates()
|
||||
{
|
||||
var monitor = Sys.ActorOf(Props.Create(() => new DeadLetterMonitorActor(_logger)));
|
||||
|
||||
// Ensure actor is started and subscribed
|
||||
monitor.Tell(GetDeadLetterCount.Instance);
|
||||
ExpectMsg<DeadLetterCountResponse>();
|
||||
|
||||
// Send 5 dead letters
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
Sys.EventStream.Publish(
|
||||
new DeadLetter($"message-{i}", Sys.DeadLetters, Sys.DeadLetters));
|
||||
}
|
||||
|
||||
AwaitAssert(() =>
|
||||
{
|
||||
monitor.Tell(GetDeadLetterCount.Instance);
|
||||
var response = ExpectMsg<DeadLetterCountResponse>();
|
||||
Assert.Equal(5, response.Count);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user