@@ -131,7 +131,7 @@ public sealed class EurekaClientTest
131131 [ Fact ]
132132 public async Task RegisterAsync_ThrowsOnUnreachableServer ( )
133133 {
134- var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
134+ using var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
135135
136136 var services = new ServiceCollection ( ) ;
137137 services . AddLogging ( options => options . SetMinimumLevel ( LogLevel . Trace ) . AddProvider ( capturingLoggerProvider ) ) ;
@@ -161,15 +161,15 @@ public async Task RegisterAsync_ThrowsOnUnreachableServer()
161161 IList < string > logMessages = capturingLoggerProvider . GetAll ( ) ;
162162
163163 logMessages . Should ( ) . BeEquivalentTo (
164- $ "DBUG { typeof ( EurekaClient ) . FullName } : Sending POST request to 'http://host-that-does-not-exist.net:9999/apps/FOOBAR' with body: " +
164+ $ "DBUG { typeof ( EurekaClient ) } : Sending POST request to 'http://host-that-does-not-exist.net:9999/apps/FOOBAR' with body: " +
165165 """{"instance":{"instanceId":"some","app":"FOOBAR","ipAddr":"127.0.0.1","port":{"@enabled":"true","$":8080},"securePort":{"@enabled":"false","$":9090},"dataCenterInfo":{"@class":"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo","name":"MyOwn"},"hostName":"localhost","overriddenstatus":"UNKNOWN","metadata":{"@class":"java.util.Collections$EmptyMap"},"lastUpdatedTimestamp":"1708427732823","lastDirtyTimestamp":"1708427732823"}}.""" ,
166- $ "WARN { typeof ( EurekaClient ) . FullName } : Failed to execute HTTP POST request to 'http://host-that-does-not-exist.net:9999/apps/FOOBAR' in attempt 1.") ;
166+ $ "WARN { typeof ( EurekaClient ) } : Failed to execute HTTP POST request to 'http://host-that-does-not-exist.net:9999/apps/FOOBAR' in attempt 1.") ;
167167 }
168168
169169 [ Fact ]
170170 public async Task RegisterAsync_ThrowsOnErrorResponse ( )
171171 {
172- var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
172+ using var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
173173
174174 var services = new ServiceCollection ( ) ;
175175 services . AddLogging ( options => options . SetMinimumLevel ( LogLevel . Trace ) . AddProvider ( capturingLoggerProvider ) ) ;
@@ -208,17 +208,17 @@ public async Task RegisterAsync_ThrowsOnErrorResponse()
208208
209209 logMessages . Should ( ) . BeEquivalentTo (
210210 [
211- $ "DBUG { typeof ( EurekaClient ) . FullName } : Sending POST request to 'http://localhost:8761/eureka/apps/FOOBAR' with body: " +
211+ $ "DBUG { typeof ( EurekaClient ) } : Sending POST request to 'http://localhost:8761/eureka/apps/FOOBAR' with body: " +
212212 """{"instance":{"instanceId":"some","app":"FOOBAR","ipAddr":"127.0.0.1","port":{"@enabled":"true","$":8080},"securePort":{"@enabled":"false","$":9090},"dataCenterInfo":{"@class":"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo","name":"MyOwn"},"hostName":"localhost","overriddenstatus":"UNKNOWN","metadata":{"@class":"java.util.Collections$EmptyMap"},"lastUpdatedTimestamp":"1708427732823","lastDirtyTimestamp":"1708427732823"}}.""" ,
213- $ "DBUG { typeof ( EurekaClient ) . FullName } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' returned status 404 in attempt 1.",
214- $ "INFO { typeof ( EurekaClient ) . FullName } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' failed with status 404: Sorry!"
213+ $ "DBUG { typeof ( EurekaClient ) } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' returned status 404 in attempt 1.",
214+ $ "INFO { typeof ( EurekaClient ) } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' failed with status 404: Sorry!"
215215 ] , options => options . WithStrictOrdering ( ) ) ;
216216 }
217217
218218 [ Fact ]
219219 public async Task RegisterAsync_ThrowsOnRetryLimitReached ( )
220220 {
221- var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
221+ using var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
222222
223223 var services = new ServiceCollection ( ) ;
224224 services . AddLogging ( options => options . SetMinimumLevel ( LogLevel . Trace ) . AddProvider ( capturingLoggerProvider ) ) ;
@@ -254,10 +254,10 @@ public async Task RegisterAsync_ThrowsOnRetryLimitReached()
254254
255255 logMessages . Should ( ) . BeEquivalentTo (
256256 [
257- $ "DBUG { typeof ( EurekaClient ) . FullName } : Sending POST request to 'http://localhost:8761/eureka/apps/FOOBAR' with body: " +
257+ $ "DBUG { typeof ( EurekaClient ) } : Sending POST request to 'http://localhost:8761/eureka/apps/FOOBAR' with body: " +
258258 """{"instance":{"instanceId":"some","app":"FOOBAR","ipAddr":"127.0.0.1","port":{"@enabled":"true","$":8080},"securePort":{"@enabled":"false","$":9090},"dataCenterInfo":{"@class":"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo","name":"MyOwn"},"hostName":"localhost","overriddenstatus":"UNKNOWN","metadata":{"@class":"java.util.Collections$EmptyMap"},"lastUpdatedTimestamp":"1708427732823","lastDirtyTimestamp":"1708427732823"}}.""" ,
259- $ "DBUG { typeof ( EurekaClient ) . FullName } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' returned status 404 in attempt 1.",
260- $ "INFO { typeof ( EurekaClient ) . FullName } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' failed with status 404: "
259+ $ "DBUG { typeof ( EurekaClient ) } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' returned status 404 in attempt 1.",
260+ $ "INFO { typeof ( EurekaClient ) } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' failed with status 404: "
261261 ] , options => options . WithStrictOrdering ( ) ) ;
262262 }
263263
@@ -266,7 +266,7 @@ public async Task RegisterAsync_LogsWarningOnCloudWithLocalhost()
266266 {
267267 using var scope = new EnvironmentVariableScope ( "VCAP_APPLICATION" , "{}" ) ;
268268
269- var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
269+ using var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
270270
271271 var services = new ServiceCollection ( ) ;
272272 services . AddLogging ( options => options . SetMinimumLevel ( LogLevel . Trace ) . AddProvider ( capturingLoggerProvider ) ) ;
@@ -293,13 +293,13 @@ public async Task RegisterAsync_LogsWarningOnCloudWithLocalhost()
293293 IList < string > logMessages = capturingLoggerProvider . GetAll ( ) ;
294294
295295 logMessages . Should ( ) . Contain (
296- $ "WARN { typeof ( EurekaClient ) . FullName } : Registering with hostname 'localhost' in containerized or cloud environments may not be valid. Please configure Eureka:Instance:HostName with a non-localhost address.") ;
296+ $ "WARN { typeof ( EurekaClient ) } : Registering with hostname 'localhost' in containerized or cloud environments may not be valid. Please configure Eureka:Instance:HostName with a non-localhost address.") ;
297297 }
298298
299299 [ Fact ]
300300 public async Task RegisterAsync_SendsRequestToServer ( )
301301 {
302- var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
302+ using var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
303303
304304 using JsonDocument requestDocument = JsonDocument . Parse ( """
305305 {
@@ -364,16 +364,16 @@ public async Task RegisterAsync_SendsRequestToServer()
364364
365365 logMessages . Should ( ) . BeEquivalentTo (
366366 [
367- $ "DBUG { typeof ( EurekaClient ) . FullName } : Sending POST request to 'http://localhost:8761/eureka/apps/FOOBAR' with body: " +
367+ $ "DBUG { typeof ( EurekaClient ) } : Sending POST request to 'http://localhost:8761/eureka/apps/FOOBAR' with body: " +
368368 """{"instance":{"instanceId":"some","app":"FOOBAR","ipAddr":"127.0.0.1","port":{"@enabled":"true","$":8080},"securePort":{"@enabled":"false","$":9090},"dataCenterInfo":{"@class":"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo","name":"MyOwn"},"hostName":"localhost","overriddenstatus":"UNKNOWN","metadata":{"@class":"java.util.Collections$EmptyMap"},"lastUpdatedTimestamp":"1708427732823","lastDirtyTimestamp":"1708427732823"}}.""" ,
369- $ "DBUG { typeof ( EurekaClient ) . FullName } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' returned status 204 in attempt 1."
369+ $ "DBUG { typeof ( EurekaClient ) } : HTTP POST request to 'http://localhost:8761/eureka/apps/FOOBAR' returned status 204 in attempt 1."
370370 ] , options => options . WithStrictOrdering ( ) ) ;
371371 }
372372
373373 [ Fact ]
374374 public async Task RegisterAsync_TriesSecondServerIfFirstOneFails ( )
375375 {
376- var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
376+ using var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
377377
378378 var services = new ServiceCollection ( ) ;
379379 services . AddLogging ( options => options . SetMinimumLevel ( LogLevel . Trace ) . AddProvider ( capturingLoggerProvider ) ) ;
@@ -408,13 +408,13 @@ public async Task RegisterAsync_TriesSecondServerIfFirstOneFails()
408408
409409 logMessages . Should ( ) . BeEquivalentTo (
410410 [
411- $ "DBUG { typeof ( EurekaClient ) . FullName } : Sending POST request to 'http://server1:8761/apps/FOOBAR' with body: " +
411+ $ "DBUG { typeof ( EurekaClient ) } : Sending POST request to 'http://server1:8761/apps/FOOBAR' with body: " +
412412 """{"instance":{"instanceId":"some","app":"FOOBAR","ipAddr":"127.0.0.1","port":{"@enabled":"true","$":8080},"securePort":{"@enabled":"false","$":9090},"dataCenterInfo":{"@class":"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo","name":"MyOwn"},"hostName":"localhost","overriddenstatus":"UNKNOWN","metadata":{"@class":"java.util.Collections$EmptyMap"},"lastUpdatedTimestamp":"1708427732823","lastDirtyTimestamp":"1708427732823"}}.""" ,
413- $ "DBUG { typeof ( EurekaClient ) . FullName } : HTTP POST request to 'http://server1:8761/apps/FOOBAR' returned status 404 in attempt 1.",
414- $ "INFO { typeof ( EurekaClient ) . FullName } : HTTP POST request to 'http://server1:8761/apps/FOOBAR' failed with status 404: ",
415- $ "DBUG { typeof ( EurekaClient ) . FullName } : Sending POST request to 'http://server2:8761/apps/FOOBAR' with body: " +
413+ $ "DBUG { typeof ( EurekaClient ) } : HTTP POST request to 'http://server1:8761/apps/FOOBAR' returned status 404 in attempt 1.",
414+ $ "INFO { typeof ( EurekaClient ) } : HTTP POST request to 'http://server1:8761/apps/FOOBAR' failed with status 404: ",
415+ $ "DBUG { typeof ( EurekaClient ) } : Sending POST request to 'http://server2:8761/apps/FOOBAR' with body: " +
416416 """{"instance":{"instanceId":"some","app":"FOOBAR","ipAddr":"127.0.0.1","port":{"@enabled":"true","$":8080},"securePort":{"@enabled":"false","$":9090},"dataCenterInfo":{"@class":"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo","name":"MyOwn"},"hostName":"localhost","overriddenstatus":"UNKNOWN","metadata":{"@class":"java.util.Collections$EmptyMap"},"lastUpdatedTimestamp":"1708427732823","lastDirtyTimestamp":"1708427732823"}}.""" ,
417- $ "DBUG { typeof ( EurekaClient ) . FullName } : HTTP POST request to 'http://server2:8761/apps/FOOBAR' returned status 204 in attempt 2."
417+ $ "DBUG { typeof ( EurekaClient ) } : HTTP POST request to 'http://server2:8761/apps/FOOBAR' returned status 204 in attempt 2."
418418 ] , options => options . WithStrictOrdering ( ) ) ;
419419 }
420420
@@ -606,7 +606,7 @@ public async Task GetApplicationsAsync_ThrowsOnBrokenJsonResponse()
606606 {
607607 const string jsonResponse = """{"applications": {""" ;
608608
609- var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
609+ using var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "Steeltoe." , StringComparison . Ordinal ) ) ;
610610
611611 var services = new ServiceCollection ( ) ;
612612 services . AddLogging ( options => options . SetMinimumLevel ( LogLevel . Trace ) . AddProvider ( capturingLoggerProvider ) ) ;
@@ -630,11 +630,10 @@ public async Task GetApplicationsAsync_ThrowsOnBrokenJsonResponse()
630630
631631 IList < string > logMessages = capturingLoggerProvider . GetAll ( ) ;
632632
633- logMessages . Should ( ) . BeEquivalentTo (
634- [
635- $ "DBUG { typeof ( EurekaClient ) . FullName } : Sending GET request to 'http://localhost:8761/eureka/apps' without request body.",
636- $ "DBUG { typeof ( EurekaClient ) . FullName } : HTTP GET request to 'http://localhost:8761/eureka/apps' returned status 200 in attempt 1.",
637- $ "DBUG { typeof ( EurekaClient ) . FullName } : Failed to deserialize HTTP response from GET 'http://localhost:8761/eureka/apps'."
633+ logMessages . Should ( ) . BeEquivalentTo ( [
634+ $ "DBUG { typeof ( EurekaClient ) } : Sending GET request to 'http://localhost:8761/eureka/apps' without request body.",
635+ $ "DBUG { typeof ( EurekaClient ) } : HTTP GET request to 'http://localhost:8761/eureka/apps' returned status 200 in attempt 1.",
636+ $ "DBUG { typeof ( EurekaClient ) } : Failed to deserialize HTTP response from GET 'http://localhost:8761/eureka/apps'."
638637 ] , options => options . WithStrictOrdering ( ) ) ;
639638 }
640639
@@ -713,7 +712,8 @@ public async Task GetByVipAsync_SendsRequestToServer()
713712 [ Fact ]
714713 public async Task Redacts_HTTP_headers ( )
715714 {
716- var capturingLoggerProvider = new CapturingLoggerProvider ( category => category . StartsWith ( "System.Net.Http.HttpClient" , StringComparison . Ordinal ) ) ;
715+ using var capturingLoggerProvider =
716+ new CapturingLoggerProvider ( category => category . StartsWith ( "System.Net.Http.HttpClient" , StringComparison . Ordinal ) ) ;
717717
718718 var services = new ServiceCollection ( ) ;
719719 services . AddLogging ( options => options . SetMinimumLevel ( LogLevel . Trace ) . AddProvider ( capturingLoggerProvider ) ) ;
0 commit comments