Стабилизировать ingress-тесты без глобального env
ci / build-test (pull_request) Successful in 2m50s
ci / build-test (pull_request) Successful in 2m50s
TelegramIngressTestHost больше не мутирует процессную переменную DEAL_SERVICE_TOKEN: токен задаётся in-memory конфигурацией хоста. Три ingress-тест-класса шли параллельно и перетирали env друг другу.
This commit is contained in:
@@ -18,6 +18,7 @@ using Grpc.Net.Client;
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
|
||||||
@@ -57,15 +58,17 @@ internal static class TelegramIngressTestHost
|
|||||||
Func<GrpcChannel, Task> scenario,
|
Func<GrpcChannel, Task> scenario,
|
||||||
RateLimitOptions? rateLimitOptions = null)
|
RateLimitOptions? rateLimitOptions = null)
|
||||||
{
|
{
|
||||||
string? originalToken = Environment.GetEnvironmentVariable(ServiceTokenEnvKey);
|
|
||||||
Environment.SetEnvironmentVariable(ServiceTokenEnvKey, serviceToken);
|
|
||||||
|
|
||||||
WebApplication? app = null;
|
WebApplication? app = null;
|
||||||
GrpcChannel? channel = null;
|
GrpcChannel? channel = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int port = TestPort.Allocate();
|
int port = TestPort.Allocate();
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder();
|
WebApplicationBuilder builder = WebApplication.CreateBuilder();
|
||||||
|
// Токен ингресса задаётся конфигурацией хоста (в приоритете над env) — без мутации процесса.
|
||||||
|
builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
|
||||||
|
{
|
||||||
|
[ServiceTokenEnvKey] = serviceToken,
|
||||||
|
});
|
||||||
builder.WebHost.ConfigureKestrel(kestrel =>
|
builder.WebHost.ConfigureKestrel(kestrel =>
|
||||||
kestrel.Listen(IPAddress.Loopback, port, listen => listen.Protocols = HttpProtocols.Http2));
|
kestrel.Listen(IPAddress.Loopback, port, listen => listen.Protocols = HttpProtocols.Http2));
|
||||||
|
|
||||||
@@ -131,8 +134,6 @@ internal static class TelegramIngressTestHost
|
|||||||
await app.StopAsync();
|
await app.StopAsync();
|
||||||
await app.DisposeAsync();
|
await app.DisposeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment.SetEnvironmentVariable(ServiceTokenEnvKey, originalToken);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user