@@ -75,7 +75,7 @@ async Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext conte
7575 }
7676
7777 // Arrange
78- var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50051 , UnaryMethod , nameof ( UnaryMethod ) ) ;
78+ var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) ) ;
7979 endpoint . Dispose ( ) ;
8080
8181 var connectTcs = new TaskCompletionSource < object ? > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
@@ -123,7 +123,7 @@ async Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext conte
123123 }
124124
125125 // Arrange
126- using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50051 , UnaryMethod , nameof ( UnaryMethod ) ) ;
126+ using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) ) ;
127127
128128 // Dispose endpoint so that channel pauses while attempting to connect to the port.
129129 endpoint . Dispose ( ) ;
@@ -160,7 +160,7 @@ Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext context)
160160 }
161161
162162 // Arrange
163- using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50051 , UnaryMethod , nameof ( UnaryMethod ) , loggerFactory : LoggerFactory ) ;
163+ using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) , loggerFactory : LoggerFactory ) ;
164164
165165 var connectionIdleTimeout = TimeSpan . FromMilliseconds ( milliseconds ) ;
166166 var channel = await BalancerHelpers . CreateChannel (
@@ -198,7 +198,7 @@ Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext context)
198198 }
199199
200200 // Arrange
201- using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50051 , UnaryMethod , nameof ( UnaryMethod ) , loggerFactory : LoggerFactory ) ;
201+ using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) , loggerFactory : LoggerFactory ) ;
202202
203203 var channel = await BalancerHelpers . CreateChannel (
204204 LoggerFactory ,
@@ -237,7 +237,6 @@ Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext context)
237237
238238 // Arrange
239239 using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > (
240- 50051 ,
241240 UnaryMethod ,
242241 nameof ( UnaryMethod ) ,
243242 loggerFactory : LoggerFactory ,
@@ -290,8 +289,8 @@ async Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext conte
290289 }
291290
292291 // Arrange
293- using var endpoint1 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50051 , UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true ) ;
294- using var endpoint2 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50052 , UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true ) ;
292+ using var endpoint1 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true ) ;
293+ using var endpoint2 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true ) ;
295294
296295 var services = new ServiceCollection ( ) ;
297296 services . AddSingleton < ResolverFactory > ( new StaticResolverFactory ( _ => new [ ]
@@ -349,7 +348,7 @@ await TestHelpers.AssertIsTrueRetryAsync(() =>
349348 } , "Wait for connections to start." ) ;
350349 foreach ( var t in activeStreams )
351350 {
352- Assert . AreEqual ( new DnsEndPoint ( "127.0.0.1" , 50051 ) , t . EndPoint ) ;
351+ Assert . AreEqual ( new DnsEndPoint ( "127.0.0.1" , endpoint1 . Address . Port ) , t . EndPoint ) ;
353352 }
354353
355354 // Act
@@ -370,7 +369,7 @@ await TestHelpers.AssertIsTrueRetryAsync(() =>
370369 activeStreams = transport . GetActiveStreams ( ) ;
371370 return activeStreams . Count == 11 ;
372371 } , "Wait for connections to start." ) ;
373- Assert . AreEqual ( new DnsEndPoint ( "127.0.0.1" , 50051 ) , activeStreams [ activeStreams . Count - 1 ] . EndPoint ) ;
372+ Assert . AreEqual ( new DnsEndPoint ( "127.0.0.1" , endpoint1 . Address . Port ) , activeStreams [ activeStreams . Count - 1 ] . EndPoint ) ;
374373
375374 tcs . SetResult ( null ) ;
376375
@@ -406,11 +405,11 @@ await TestHelpers.AssertIsTrueRetryAsync(() =>
406405 Logger . LogInformation ( $ "Next call goes to fallback address.") ;
407406 var reply = await client . UnaryCall ( new HelloRequest { Name = "Balancer" } ) . ResponseAsync . TimeoutAfter ( TimeSpan . FromSeconds ( 20 ) ) ;
408407 Assert . AreEqual ( "Balancer" , reply . Message ) ;
409- Assert . AreEqual ( "127.0.0.1:50052 " , host ) ;
408+ Assert . AreEqual ( $ "127.0.0.1:{ endpoint2 . Address . Port } ", host ) ;
410409
411410 activeStreams = transport . GetActiveStreams ( ) ;
412411 Assert . AreEqual ( 1 , activeStreams . Count ) ;
413- Assert . AreEqual ( new DnsEndPoint ( "127.0.0.1" , 50052 ) , activeStreams [ 0 ] . EndPoint ) ;
412+ Assert . AreEqual ( new DnsEndPoint ( "127.0.0.1" , endpoint2 . Address . Port ) , activeStreams [ 0 ] . EndPoint ) ;
414413 }
415414
416415#if NET7_0_OR_GREATER
@@ -436,8 +435,8 @@ Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext context)
436435 var cert = new X509Certificate2 ( certPath , "11111" ) ;
437436
438437 // Arrange
439- using var endpoint1 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50051 , UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true , certificate : cert ) ;
440- using var endpoint2 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50052 , UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true , certificate : cert ) ;
438+ using var endpoint1 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true , certificate : cert ) ;
439+ using var endpoint2 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true , certificate : cert ) ;
441440
442441 var services = new ServiceCollection ( ) ;
443442 services . AddSingleton ( ( ResolverFactory ) new StaticResolverFactory ( _ => ( new [ ]
@@ -491,13 +490,13 @@ Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext context)
491490 Assert . AreEqual ( "localhost" , host ) ;
492491 Assert . AreEqual ( SslPolicyErrors . None , callbackPolicyErrors ) ;
493492 Assert . AreEqual ( IPAddress . Parse ( "127.0.0.1" ) , ipAddress ) ;
494- Assert . IsTrue ( port == 50051 || port == 50052 ) ;
493+ Assert . IsTrue ( port == endpoint1 . Address . Port || port == endpoint2 . Address . Port ) ;
495494
496495 ports . Add ( port ! . Value ) ;
497496 }
498497
499- Assert . IsTrue ( ports . Contains ( 50051 ) , "Has 50051 " ) ;
500- Assert . IsTrue ( ports . Contains ( 50052 ) , "Has 50052 " ) ;
498+ Assert . IsTrue ( ports . Contains ( endpoint1 . Address . Port ) , $ "Has { endpoint1 . Address . Port } ") ;
499+ Assert . IsTrue ( ports . Contains ( endpoint2 . Address . Port ) , $ "Has { endpoint2 . Address . Port } ") ;
501500
502501 static BalancerAddress CreateAddress ( Uri address , string hostOverride )
503502 {
@@ -523,8 +522,8 @@ Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext context)
523522 metadata . Add ( "Authorization" , $ "Bearer TEST") ;
524523 return Task . CompletedTask ;
525524 } ) ;
526- using var endpoint1 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50051 , UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true ) ;
527- using var endpoint2 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50052 , UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true ) ;
525+ using var endpoint1 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true ) ;
526+ using var endpoint2 = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) , HttpProtocols . Http1AndHttp2 , isHttps : true ) ;
528527
529528 var services = new ServiceCollection ( ) ;
530529 services . AddSingleton < ResolverFactory > ( new StaticResolverFactory ( _ => new [ ]
@@ -706,7 +705,7 @@ Task<HelloReply> UnaryMethod(HelloRequest request, ServerCallContext context)
706705 }
707706
708707 // Arrange
709- using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( 50051 , UnaryMethod , nameof ( UnaryMethod ) ) ;
708+ using var endpoint = BalancerHelpers . CreateGrpcEndpoint < HelloRequest , HelloReply > ( UnaryMethod , nameof ( UnaryMethod ) ) ;
710709
711710 var channel = await BalancerHelpers . CreateChannel (
712711 LoggerFactory ,
0 commit comments