Files
GmRelayBot/tests/GmRelay.Bot.Tests/Infrastructure/Health/BotHealthCheckHostedServiceTests.cs
T
Toutsu 3bea327043
PR Checks / test-and-build (pull_request) Successful in 8m53s
feat: add health check endpoints for Bot and Web
- Web: add /health endpoint with PostgreSQL readiness check (returns 200+JSON or 503)
- Web: add /alive endpoint for liveness probe
- Bot: add BotHealthCheckHostedService serving /health on port 8081 via HttpListener
- Bot: expose port 8081 in Dockerfile and install wget for healthcheck
- compose.yaml: add healthcheck sections for bot and web services
- tests: add TDD tests for both health endpoints

Bump version -> 1.16.0

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 10:54:22 +03:00

43 lines
1.2 KiB
C#

using System.Net;
using GmRelay.Bot.Infrastructure.Health;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging.Abstractions;
namespace GmRelay.Bot.Tests.Infrastructure.Health;
public sealed class BotHealthCheckHostedServiceTests : IDisposable
{
private readonly BotHealthCheckHostedService _service;
public BotHealthCheckHostedServiceTests()
{
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
["HealthCheck:Prefix"] = "http://localhost:8081/"
})
.Build();
_service = new BotHealthCheckHostedService(
NullLogger<BotHealthCheckHostedService>.Instance,
config);
}
public void Dispose()
{
_service.StopAsync(CancellationToken.None).Wait(TimeSpan.FromSeconds(5));
}
[Fact]
public async Task HealthEndpoint_ShouldReturn200_WhenServiceIsRunning()
{
await _service.StartAsync(CancellationToken.None);
using var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(5);
var response = await client.GetAsync("http://localhost:8081/health");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}