Finish: Phase 33 — Alert Quality Analytics
This commit is contained in:
@@ -7,6 +7,7 @@ using Microsoft.Extensions.Options;
|
||||
public class TestingAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
||||
{
|
||||
public const string SchemeName = "Testing";
|
||||
public const string DefaultTestUserId = "00000000-0000-0000-0000-000000000001";
|
||||
|
||||
public TestingAuthHandler(
|
||||
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
||||
@@ -22,7 +23,7 @@ public class TestingAuthHandler : AuthenticationHandler<AuthenticationSchemeOpti
|
||||
var role = roleHeader.ToString();
|
||||
var userId = Request.Headers.TryGetValue("X-Test-User-Id", out var idHeader)
|
||||
? idHeader.ToString()
|
||||
: Guid.NewGuid().ToString();
|
||||
: DefaultTestUserId;
|
||||
|
||||
var claims = new[]
|
||||
{
|
||||
|
||||
@@ -18,12 +18,12 @@ public static class RabbitMqTestHelper
|
||||
using var connection = factory.CreateConnection("test-queue-purge");
|
||||
using var channel = connection.CreateModel();
|
||||
|
||||
foreach (var queue in new[]
|
||||
{
|
||||
"alerts.paging.queue",
|
||||
"alerts.paging.dlq",
|
||||
"alerts.escalation.queue",
|
||||
})
|
||||
// x-message-ttl is immutable once the queue exists. A concurrently running dev API
|
||||
// (300000 ms) can recreate the DLQ after the test host provisions 5000 ms, leaving
|
||||
// escalation stuck until the 5-minute TTL expires — far beyond the test poll window.
|
||||
RecreatePagingDlq(channel, o.PagingAckTimeoutMs);
|
||||
|
||||
foreach (var queue in new[] { "alerts.paging.queue", "alerts.escalation.queue" })
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -35,4 +35,35 @@ public static class RabbitMqTestHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RecreatePagingDlq(IModel channel, int pagingAckTimeoutMs)
|
||||
{
|
||||
const string dlq = "alerts.paging.dlq";
|
||||
|
||||
try
|
||||
{
|
||||
channel.QueueDelete(dlq, ifUnused: false, ifEmpty: false);
|
||||
}
|
||||
catch (OperationInterruptedException)
|
||||
{
|
||||
// Queue may not exist yet on a cold broker.
|
||||
}
|
||||
|
||||
channel.ExchangeDeclare(
|
||||
RabbitMqTopologyProvisioner.Exchange,
|
||||
ExchangeType.Direct,
|
||||
durable: true);
|
||||
|
||||
channel.QueueDeclare(
|
||||
queue: dlq,
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: new Dictionary<string, object>
|
||||
{
|
||||
["x-message-ttl"] = pagingAckTimeoutMs,
|
||||
["x-dead-letter-exchange"] = RabbitMqTopologyProvisioner.Exchange,
|
||||
["x-dead-letter-routing-key"] = RabbitMqTopologyProvisioner.EscalKey,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[Collection("Integration")]
|
||||
public class RabbitMqOptionsTests
|
||||
{
|
||||
private readonly ApiFixture _fixture;
|
||||
|
||||
public RabbitMqOptionsTests(ApiFixture fixture) => _fixture = fixture;
|
||||
|
||||
[Fact]
|
||||
public void PagingAckTimeoutMs_IsConfiguredForIntegrationTests()
|
||||
{
|
||||
using var scope = _fixture.Services.CreateScope();
|
||||
var opts = scope.ServiceProvider.GetRequiredService<Microsoft.Extensions.Options.IOptions<RabbitMqOptions>>().Value;
|
||||
opts.PagingAckTimeoutMs.Should().Be(5000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user