fix tests. new product advisories enhancements

This commit is contained in:
master
2026-01-25 19:11:36 +02:00
parent c70e83719e
commit 6e687b523a
504 changed files with 40610 additions and 3785 deletions

View File

@@ -13,10 +13,16 @@ namespace StellaOps.Chaos.Router.Tests.Fixtures;
/// <summary>
/// Test fixture providing an HTTP client for router chaos testing.
/// </summary>
/// <remarks>
/// In xUnit v3, throwing SkipException from fixture InitializeAsync causes test failures
/// rather than skips. Instead, we track availability and let tests call EnsureRouterAvailable()
/// to skip when infrastructure is unavailable.
/// </remarks>
public class RouterTestFixture : IAsyncLifetime
{
private readonly HttpClient _client;
private readonly string _routerUrl;
private string? _skipReason;
public RouterTestFixture()
{
@@ -29,7 +35,29 @@ public class RouterTestFixture : IAsyncLifetime
};
}
public HttpClient CreateClient() => _client;
/// <summary>
/// Gets whether the router is available. Call <see cref="EnsureRouterAvailable"/> at the
/// start of each test to skip when infrastructure is unavailable.
/// </summary>
public bool IsRouterAvailable => _skipReason is null;
/// <summary>
/// Throws SkipException if the router is not available.
/// Call this at the start of each test method to properly skip tests when infrastructure is unavailable.
/// </summary>
public void EnsureRouterAvailable()
{
if (_skipReason is not null)
{
throw SkipException.ForSkip(_skipReason);
}
}
public HttpClient CreateClient()
{
EnsureRouterAvailable();
return _client;
}
public string RouterUrl => _routerUrl;
@@ -38,6 +66,7 @@ public class RouterTestFixture : IAsyncLifetime
/// </summary>
public async Task ConfigureLowLimitsAsync()
{
EnsureRouterAvailable();
// In real scenario, this would configure the router via admin endpoint
// For now, assume limits are pre-configured for chaos testing
await ValueTask.CompletedTask;
@@ -64,11 +93,11 @@ public class RouterTestFixture : IAsyncLifetime
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
_ = await _client.GetAsync("/", cts.Token);
_skipReason = null;
}
catch (Exception ex) when (ex is HttpRequestException || ex is TaskCanceledException || ex is OperationCanceledException)
{
throw SkipException.ForSkip(
$"Router not reachable at '{_routerUrl}'. Set ROUTER_URL or start the router service to run chaos tests.");
_skipReason = $"Router not reachable at '{_routerUrl}'. Set ROUTER_URL or start the router service to run chaos tests.";
}
}
@@ -89,6 +118,8 @@ public class RouterWithValkeyFixture : RouterTestFixture
public async Task StartValkeyAsync()
{
EnsureRouterAvailable();
if (_valkeyContainer is null)
{
_valkeyContainer = new Testcontainers.Redis.RedisBuilder()
@@ -106,6 +137,8 @@ public class RouterWithValkeyFixture : RouterTestFixture
public async Task StopValkeyAsync()
{
EnsureRouterAvailable();
if (_valkeyContainer is not null && _valkeyRunning)
{
await _valkeyContainer.StopAsync();
@@ -115,6 +148,7 @@ public class RouterWithValkeyFixture : RouterTestFixture
public async Task ConfigureValkeyLatencyAsync(TimeSpan latency)
{
EnsureRouterAvailable();
// Configure artificial latency via Valkey DEBUG SLEEP
// In production, use network simulation tools like tc or toxiproxy
await ValueTask.CompletedTask;

View File

@@ -26,7 +26,12 @@ public class ValkeyFailureTests : IClassFixture<RouterWithValkeyFixture>, IAsync
public async ValueTask InitializeAsync()
{
await _fixture.StartValkeyAsync();
// Only start Valkey if the router is available.
// If the router is not available, tests will be skipped when they call fixture methods.
if (_fixture.IsRouterAvailable)
{
await _fixture.StartValkeyAsync();
}
}
public ValueTask DisposeAsync()