Files
natsdotnet/tests/NATS.E2E.Tests/Infrastructure/MonitorServerFixture.cs
Joseph Doherty 8ad2172e3c test: add E2E monitoring endpoint tests (varz, connz, healthz)
Replace Task.Delay polling with PeriodicTimer in NatsServerProcess readiness
checks and extend StartAsync to also TCP-poll the monitor port when enabled,
so MonitorServerFixture is guaranteed ready before tests run.
2026-03-12 19:10:33 -04:00

37 lines
1.1 KiB
C#

using NATS.Client.Core;
using System.Net.Http;
namespace NATS.E2E.Tests.Infrastructure;
public sealed class MonitorServerFixture : IAsyncLifetime
{
private NatsServerProcess _server = null!;
public int Port => _server.Port;
public int MonitorPort => _server.MonitorPort!.Value;
public HttpClient MonitorClient { get; private set; } = null!;
public async Task InitializeAsync()
{
_server = new NatsServerProcess(enableMonitoring: true);
await _server.StartAsync(); // StartAsync polls both the NATS port and the monitor TCP port before returning
MonitorClient = new HttpClient { BaseAddress = new Uri($"http://127.0.0.1:{MonitorPort}") };
}
public async Task DisposeAsync()
{
MonitorClient?.Dispose();
await _server.DisposeAsync();
}
public NatsConnection CreateClient()
{
return new NatsConnection(new NatsOpts { Url = $"nats://127.0.0.1:{Port}" });
}
}
[CollectionDefinition("E2E-Monitor")]
public class MonitorCollection : ICollectionFixture<MonitorServerFixture>;