@@ -25,13 +25,13 @@ internal sealed class MockMetricsCollector : IDisposable
2525 private readonly BlockingCollection < List < Collected > > _metricsSnapshots = new ( 10 ) ; // bounded to avoid memory leak; contains protobuf type
2626 private Func < ICollection < Collected > , bool > ? _additionalEntriesExpectation ;
2727
28- public MockMetricsCollector ( ITestOutputHelper output , string host = "localhost" )
28+ private MockMetricsCollector ( ITestOutputHelper output , string host )
2929 {
3030 _output = output ;
3131#if NETFRAMEWORK
3232 _listener = new ( output , HandleHttpRequests , host , "/v1/metrics/" ) ;
3333#else
34- _listener = new ( output , nameof ( MockMetricsCollector ) , new PathHandler ( HandleHttpRequests , "/v1/metrics" ) ) ;
34+ _listener = new ( output , nameof ( MockMetricsCollector ) , new PathHandler ( HandleHttpRequests , "/v1/metrics" ) , MockCollectorHealthZ . CreateHealthZHandler ( ) ) ;
3535#endif
3636 }
3737
@@ -42,6 +42,21 @@ public MockMetricsCollector(ITestOutputHelper output, string host = "localhost")
4242
4343 public OtlpResourceExpector ResourceExpector { get ; } = new ( ) ;
4444
45+ #if NET
46+ public static async Task < MockMetricsCollector > InitializeAsync ( ITestOutputHelper output , string host = "localhost" )
47+ #else
48+ public static Task < MockMetricsCollector > InitializeAsync ( ITestOutputHelper output , string host = "localhost" )
49+ #endif
50+ {
51+ var collector = new MockMetricsCollector ( output , host ) ;
52+ #if NET
53+ await MockCollectorHealthZ . WarmupHealthZEndpoint ( output , host , collector . Port ) ;
54+ return collector ;
55+ #else
56+ return Task . FromResult ( collector ) ;
57+ #endif
58+ }
59+
4560 public void Dispose ( )
4661 {
4762 WriteOutput ( "Shutting down." ) ;
0 commit comments