@@ -9,11 +9,12 @@ namespace Prometheus.Client.MetricServer.NetCore.Tests
99{
1010 public class MetricServerTests
1111 {
12+ private const int _port = 5050 ;
13+
1214 [ Fact ]
1315 public void Start_Stop_IsRunning ( )
1416 {
15- const int port = 9000 ;
16- var metricServer = new MetricServer ( new CollectorRegistry ( ) , new MetricServerOptions { Port = port } ) ;
17+ var metricServer = new MetricServer ( new CollectorRegistry ( ) , new MetricServerOptions { Port = _port } ) ;
1718 metricServer . Start ( ) ;
1819 Assert . True ( metricServer . IsRunning ) ;
1920 metricServer . Stop ( ) ;
@@ -23,13 +24,13 @@ public void Start_Stop_IsRunning()
2324 [ Fact ]
2425 public async Task Base_MapPath ( )
2526 {
26- const int port = 9000 ;
27- var metricServer = new MetricServer ( new CollectorRegistry ( ) , new MetricServerOptions { Port = port } ) ;
27+
28+ var metricServer = new MetricServer ( new CollectorRegistry ( ) , new MetricServerOptions { Port = _port } ) ;
2829 metricServer . Start ( ) ;
2930
3031 using ( var httpClient = new HttpClient ( ) )
3132 {
32- var response = await httpClient . GetStringAsync ( $ "http://localhost:{ port } /metrics") ;
33+ var response = await httpClient . GetStringAsync ( $ "http://localhost:{ _port } /metrics") ;
3334 Assert . False ( string . IsNullOrEmpty ( response ) ) ;
3435 }
3536
@@ -39,15 +40,14 @@ public async Task Base_MapPath()
3940 [ Fact ]
4041 public async Task MapPath_WithEndSlash ( )
4142 {
42- const int port = 9000 ;
4343 var metricServer = new MetricServer (
4444 new CollectorRegistry ( ) ,
45- new MetricServerOptions { Port = port , MapPath = "/test" } ) ;
45+ new MetricServerOptions { Port = _port , MapPath = "/test" } ) ;
4646 metricServer . Start ( ) ;
4747
4848 using ( var httpClient = new HttpClient ( ) )
4949 {
50- var response = await httpClient . GetStringAsync ( $ "http://localhost:{ port } /test/") ;
50+ var response = await httpClient . GetStringAsync ( $ "http://localhost:{ _port } /test/") ;
5151 Assert . False ( string . IsNullOrEmpty ( response ) ) ;
5252 }
5353
@@ -57,10 +57,9 @@ public async Task MapPath_WithEndSlash()
5757 [ Fact ]
5858 public void Wrong_MapPath ( )
5959 {
60- const int port = 9000 ;
6160 Assert . Throws < ArgumentException > ( ( ) => new MetricServer (
6261 new CollectorRegistry ( ) ,
63- new MetricServerOptions { Port = port , MapPath = "temp" } ) ) ;
62+ new MetricServerOptions { Port = _port , MapPath = "temp" } ) ) ;
6463 }
6564
6665 [ Theory ]
@@ -69,15 +68,14 @@ public void Wrong_MapPath()
6968 [ InlineData ( "/metrics965" ) ]
7069 public async Task MapPath ( string mapPath )
7170 {
72- const int port = 9000 ;
7371 var metricServer = new MetricServer (
7472 new CollectorRegistry ( ) ,
75- new MetricServerOptions { Port = port , MapPath = mapPath } ) ;
73+ new MetricServerOptions { Port = _port , MapPath = mapPath } ) ;
7674 metricServer . Start ( ) ;
7775
7876 using ( var httpClient = new HttpClient ( ) )
7977 {
80- var response = await httpClient . GetStringAsync ( $ "http://localhost:{ port } " + mapPath ) ;
78+ var response = await httpClient . GetStringAsync ( $ "http://localhost:{ _port } " + mapPath ) ;
8179 Assert . False ( string . IsNullOrEmpty ( response ) ) ;
8280 }
8381
@@ -87,10 +85,9 @@ public async Task MapPath(string mapPath)
8785 [ Fact ]
8886 public async Task FindMetric ( )
8987 {
90- const int port = 9000 ;
9188 var registry = new CollectorRegistry ( ) ;
9289 var factory = new MetricFactory ( registry ) ;
93- var metricServer = new MetricServer ( registry , new MetricServerOptions { Port = port } ) ;
90+ var metricServer = new MetricServer ( registry , new MetricServerOptions { Port = _port } ) ;
9491
9592 metricServer . Start ( ) ;
9693
@@ -100,7 +97,7 @@ public async Task FindMetric()
10097
10198 using ( var httpClient = new HttpClient ( ) )
10299 {
103- var response = await httpClient . GetStringAsync ( $ "http://localhost:{ port } /metrics") ;
100+ var response = await httpClient . GetStringAsync ( $ "http://localhost:{ _port } /metrics") ;
104101 Assert . Contains ( metricName , response ) ;
105102 }
106103
@@ -110,13 +107,12 @@ public async Task FindMetric()
110107 [ Fact ]
111108 public async Task Url_NotFound ( )
112109 {
113- const int port = 9000 ;
114- var metricServer = new MetricServer ( new CollectorRegistry ( ) , new MetricServerOptions { Port = port } ) ;
110+ var metricServer = new MetricServer ( new CollectorRegistry ( ) , new MetricServerOptions { Port = _port } ) ;
115111 metricServer . Start ( ) ;
116112
117113 using ( var httpClient = new HttpClient ( ) )
118114 {
119- var response = await httpClient . GetAsync ( $ "http://localhost:{ port } ") ;
115+ var response = await httpClient . GetAsync ( $ "http://localhost:{ _port } ") ;
120116 Assert . Equal ( HttpStatusCode . NotFound , response . StatusCode ) ;
121117 }
122118
0 commit comments