- Rename tests/NATS.Server.Tests -> tests/NATS.Server.Core.Tests - Update solution file, InternalsVisibleTo, and csproj references - Remove JETSTREAM_INTEGRATION_MATRIX and NATS.NKeys from csproj (moved to JetStream.Tests and Auth.Tests) - Update all namespaces from NATS.Server.Tests.* to NATS.Server.Core.Tests.* - Replace private GetFreePort/ReadUntilAsync helpers with TestUtilities calls - Fix stale namespace in Transport.Tests/NetworkingGoParityTests.cs
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using System.Reflection;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using NATS.Server.Monitoring;
|
|
|
|
namespace NATS.Server.Core.Tests.Internal;
|
|
|
|
public class InternalDsPeriodicSamplerParityTests
|
|
{
|
|
[Fact]
|
|
[SlopwatchSuppress("SW004", "Test must observe a real 1-second CPU sampling timer tick; wall-clock elapsed time is the observable under test")]
|
|
public async Task VarzHandler_uses_periodic_background_cpu_sampler()
|
|
{
|
|
var options = new NatsOptions { Host = "127.0.0.1", Port = 0 };
|
|
var server = new NatsServer(options, NullLoggerFactory.Instance);
|
|
using var cts = new CancellationTokenSource();
|
|
_ = server.StartAsync(cts.Token);
|
|
await server.WaitForReadyAsync();
|
|
|
|
try
|
|
{
|
|
using var handler = new VarzHandler(server, options, NullLoggerFactory.Instance);
|
|
var field = typeof(VarzHandler).GetField("_lastCpuSampleTime", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
field.ShouldNotBeNull();
|
|
|
|
var before = (DateTime)field!.GetValue(handler)!;
|
|
await Task.Delay(TimeSpan.FromMilliseconds(1200));
|
|
var after = (DateTime)field.GetValue(handler)!;
|
|
|
|
after.ShouldBeGreaterThan(before);
|
|
}
|
|
finally
|
|
{
|
|
await cts.CancelAsync();
|
|
server.Dispose();
|
|
}
|
|
}
|
|
}
|