Fix most recent fix for ci test
CI / backend (push) Successful in 9m19s
CI / frontend (push) Successful in 1m43s

This commit is contained in:
2026-08-10 15:24:47 +08:00
parent aee4cadf69
commit 5c28516412
2 changed files with 17 additions and 8 deletions
@@ -81,16 +81,20 @@ public class GatewayApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
await GatewayDbResetHelper.ResetAsync(migrateDb); await GatewayDbResetHelper.ResetAsync(migrateDb);
} }
using var scope = Services.CreateScope();
var redis = scope.ServiceProvider.GetRequiredService<IConnectionMultiplexer>();
var server = redis.GetServer(redis.GetEndPoints().First());
// Flush only the gateway test DB index — do not FlushAll (would wipe API test DB 1). // Flush only the gateway test DB index — do not FlushAll (would wipe API test DB 1).
// Must run before Services is touched: host startup saturates the thread pool and
// causes StackExchange.Redis TimeoutException on FLUSHDB under CI load.
var dbIndex = 2; var dbIndex = 2;
var cfg = RedisConnection.Split(',').FirstOrDefault(p => p.StartsWith("defaultDatabase=", StringComparison.OrdinalIgnoreCase)); var cfg = RedisConnection.Split(',').FirstOrDefault(p => p.StartsWith("defaultDatabase=", StringComparison.OrdinalIgnoreCase));
if (cfg is not null && int.TryParse(cfg.Split('=')[1], out var parsed)) if (cfg is not null && int.TryParse(cfg.Split('=')[1], out var parsed))
dbIndex = parsed; dbIndex = parsed;
await using (var redis = await ConnectionMultiplexer.ConnectAsync(RedisConnection))
{
var server = redis.GetServer(redis.GetEndPoints().First());
await server.FlushDatabaseAsync(dbIndex); await server.FlushDatabaseAsync(dbIndex);
} }
}
protected override void ConfigureClient(HttpClient client) protected override void ConfigureClient(HttpClient client)
{ {
@@ -129,11 +129,16 @@ public class ApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
VirtualHost = "vigilcare_test", VirtualHost = "vigilcare_test",
}); });
using var scope = Services.CreateScope(); // Flush Redis before starting the host. Accessing Services boots many hosted
var redis = scope.ServiceProvider.GetRequiredService<IConnectionMultiplexer>(); // services that saturate the thread pool; FLUSHDB on the shared multiplexer
// then times out waiting for a reply that already arrived (see SE.Redis
// TimeoutException: last-in/cur-in stuck, QueuedItems > 0).
await using (var redis = await ConnectionMultiplexer.ConnectAsync(RedisConnection))
{
var server = redis.GetServer(redis.GetEndPoints().First()); var server = redis.GetServer(redis.GetEndPoints().First());
await server.FlushDatabaseAsync(1); await server.FlushDatabaseAsync(1);
} }
}
protected override void ConfigureClient(HttpClient client) protected override void ConfigureClient(HttpClient client)
{ {