11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4- using System ;
5- using System . Collections . Generic ;
64using System . Globalization ;
7- using System . Linq ;
85using System . Net ;
96using System . Net . Sockets ;
10- using System . Threading . Tasks ;
11- using Xunit ;
127using Microsoft . AspNetCore . Server . IIS . FunctionalTests . Utilities ;
138using Microsoft . AspNetCore . Server . IntegrationTesting ;
149using Microsoft . AspNetCore . Testing ;
@@ -58,11 +53,11 @@ public async Task EnvVarInWebConfig_Valid(TestVariant variant)
5853 var port = GetUnusedRandomPort ( ) ;
5954 deploymentParameters . WebConfigBasedEnvironmentVariables [ "ASPNETCORE_PORT" ] = port . ToString ( CultureInfo . InvariantCulture ) ;
6055
61- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
62-
63- var responseText = await deploymentResult . HttpClient . GetStringAsync ( "/ServerAddresses" ) ;
64-
65- Assert . Equal ( port , new Uri ( responseText ) . Port ) ;
56+ await RunTest ( deploymentParameters , async deploymentResult =>
57+ {
58+ var responseText = await deploymentResult . HttpClient . GetStringAsync ( "/ServerAddresses" ) ;
59+ Assert . Equal ( port , new Uri ( responseText ) . Port ) ;
60+ } ) ;
6661 }
6762
6863 [ ConditionalTheory ]
@@ -73,12 +68,13 @@ public async Task EnvVarInWebConfig_Empty(TestVariant variant)
7368 var deploymentParameters = Fixture . GetBaseDeploymentParameters ( variant ) ;
7469 deploymentParameters . WebConfigBasedEnvironmentVariables [ "ASPNETCORE_PORT" ] = string . Empty ;
7570
76- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
77-
78- var responseText = await deploymentResult . HttpClient . GetStringAsync ( "/ServerAddresses" ) ;
71+ await RunTest ( deploymentParameters , async deploymentResult =>
72+ {
73+ var responseText = await deploymentResult . HttpClient . GetStringAsync ( "/ServerAddresses" ) ;
7974
80- // If env var is empty, ANCM should assign a random port (same as no env var)
81- Assert . InRange ( new Uri ( responseText ) . Port , _minPort , _maxPort ) ;
75+ // If env var is empty, ANCM should assign a random port (same as no env var)
76+ Assert . InRange ( new Uri ( responseText ) . Port , _minPort , _maxPort ) ;
77+ } ) ;
8278 }
8379
8480 [ ConditionalTheory ]
@@ -89,11 +85,11 @@ public async Task EnvVarInWebConfig_Invalid(TestVariant variant, string port)
8985 var deploymentParameters = Fixture . GetBaseDeploymentParameters ( variant ) ;
9086 deploymentParameters . WebConfigBasedEnvironmentVariables [ "ASPNETCORE_PORT" ] = port ;
9187
92- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
93-
94- var response = await deploymentResult . HttpClient . GetAsync ( "/ServerAddresses" ) ;
95-
96- Assert . Equal ( HttpStatusCode . BadGateway , response . StatusCode ) ;
88+ await RunTest ( deploymentParameters , async deploymentResult =>
89+ {
90+ var response = await deploymentResult . HttpClient . GetAsync ( "/ServerAddresses" ) ;
91+ Assert . Equal ( HttpStatusCode . BadGateway , response . StatusCode ) ;
92+ } ) ;
9793 }
9894
9995 [ ConditionalTheory ]
@@ -104,45 +100,46 @@ public async Task ShutdownMultipleTimesWorks(TestVariant variant)
104100 // Must publish to set env vars in web.config
105101 var deploymentParameters = Fixture . GetBaseDeploymentParameters ( variant ) ;
106102
107- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
108-
109- // Shutdown once
110- var response = await deploymentResult . HttpClient . GetAsync ( "/Shutdown" ) ;
111-
112- // Wait for server to start again.
113- int i ;
114- for ( i = 0 ; i < 10 ; i ++ )
103+ await RunTest ( deploymentParameters , async deploymentResult =>
115104 {
116- // ANCM should eventually recover from being shutdown multiple times.
117- response = await deploymentResult . HttpClient . GetAsync ( "/HelloWorld" ) ;
118- if ( response . IsSuccessStatusCode )
105+ // Shutdown once
106+ var response = await deploymentResult . HttpClient . GetAsync ( "/Shutdown" ) ;
107+
108+ // Wait for server to start again.
109+ int i ;
110+ for ( i = 0 ; i < 10 ; i ++ )
119111 {
120- break ;
112+ // ANCM should eventually recover from being shutdown multiple times.
113+ response = await deploymentResult . HttpClient . GetAsync ( "/HelloWorld" ) ;
114+ if ( response . IsSuccessStatusCode )
115+ {
116+ break ;
117+ }
121118 }
122- }
123119
124- if ( i == 10 )
125- {
126- // Didn't restart after 10 retries
127- Assert . False ( true ) ;
128- }
120+ if ( i == 10 )
121+ {
122+ // Didn't restart after 10 retries
123+ Assert . False ( true ) ;
124+ }
129125
130- // Shutdown again
131- response = await deploymentResult . HttpClient . GetAsync ( "/Shutdown" ) ;
126+ // Shutdown again
127+ response = await deploymentResult . HttpClient . GetAsync ( "/Shutdown" ) ;
132128
133- // return if server starts again.
134- for ( i = 0 ; i < 10 ; i ++ )
135- {
136- // ANCM should eventually recover from being shutdown multiple times.
137- response = await deploymentResult . HttpClient . GetAsync ( "/HelloWorld" ) ;
138- if ( response . IsSuccessStatusCode )
129+ // return if server starts again.
130+ for ( i = 0 ; i < 10 ; i ++ )
139131 {
140- return ;
132+ // ANCM should eventually recover from being shutdown multiple times.
133+ response = await deploymentResult . HttpClient . GetAsync ( "/HelloWorld" ) ;
134+ if ( response . IsSuccessStatusCode )
135+ {
136+ return ;
137+ }
141138 }
142- }
143139
144- // Test failure if this happens.
145- Assert . False ( true ) ;
140+ // Test failure if this happens.
141+ Assert . False ( true ) ;
142+ } ) ;
146143 }
147144
148145 private static int GetUnusedRandomPort ( )
0 commit comments