@@ -36,11 +36,14 @@ public class StandbyManagerTests : IDisposable
36
36
private TestServer _httpServer ;
37
37
private string _expectedHostId ;
38
38
private WebHostSettings _webHostSettings ;
39
+ private string _testRootPath ;
39
40
40
41
public StandbyManagerTests ( )
41
42
{
42
43
_settingsManager = ScriptSettingsManager . Instance ;
44
+ _testRootPath = Path . Combine ( Path . GetTempPath ( ) , "StandbyManagerTests" ) ;
43
45
ResetEnvironment ( ) ;
46
+ CleanupTestDirectory ( ) ;
44
47
}
45
48
46
49
[ Fact ]
@@ -110,7 +113,7 @@ public async Task StandbyMode_EndToEnd()
110
113
} ;
111
114
using ( var env = new TestScopedEnvironmentVariable ( vars ) )
112
115
{
113
- await InitializeTestHost ( "StandbyModeTest " ) ;
116
+ InitializeTestHost ( "Windows " ) ;
114
117
115
118
await VerifyWarmupSucceeds ( ) ;
116
119
await VerifyWarmupSucceeds ( restart : true ) ;
@@ -163,12 +166,11 @@ public async Task StandbyMode_EndToEnd_LinuxContainer()
163
166
{ EnvironmentSettingNames . AzureWebsiteContainerReady , null } ,
164
167
{ EnvironmentSettingNames . AzureWebsiteSku , "Dynamic" } ,
165
168
{ EnvironmentSettingNames . AzureWebsiteZipDeployment , null } ,
166
- { EnvironmentSettingNames . AzureWebJobsSecretStorageType , "Blob" } ,
167
169
{ "AzureWebEncryptionKey" , "0F75CA46E7EBDD39E4CA6B074D1F9A5972B849A55F91A248" }
168
170
} ;
169
171
using ( var env = new TestScopedEnvironmentVariable ( vars ) )
170
172
{
171
- await InitializeTestHost ( "StandbyModeTest_Linux " ) ;
173
+ InitializeTestHost ( "Linux " ) ;
172
174
173
175
await VerifyWarmupSucceeds ( ) ;
174
176
await VerifyWarmupSucceeds ( restart : true ) ;
@@ -178,12 +180,21 @@ public async Task StandbyMode_EndToEnd_LinuxContainer()
178
180
179
181
// immediately call a function - expect the call to block until
180
182
// the host is fully specialized
183
+ // the Unauthorized is expected since we havne't specified the key
184
+ // it's enough here to ensure we don't get a 404
185
+ var request = new HttpRequestMessage ( HttpMethod . Get , $ "api/httptrigger") ;
186
+ request . Headers . Add ( ScriptConstants . AntaresColdStartHeaderName , "1" ) ;
187
+ var response = await _httpClient . SendAsync ( request ) ;
188
+ Assert . Equal ( HttpStatusCode . Unauthorized , response . StatusCode ) ;
189
+
190
+ // now that the host is initialized, send a valid key
191
+ // and expect success
181
192
var secretManager = _httpServer . Host . Services . GetService < ISecretManager > ( ) ;
182
193
var keys = await secretManager . GetFunctionSecretsAsync ( "HttpTrigger" ) ;
183
194
string key = keys . First ( ) . Value ;
184
- var request = new HttpRequestMessage ( HttpMethod . Get , $ "api/httptrigger?code={ key } ") ;
195
+ request = new HttpRequestMessage ( HttpMethod . Get , $ "api/httptrigger?code={ key } ") ;
185
196
request . Headers . Add ( ScriptConstants . AntaresColdStartHeaderName , "1" ) ;
186
- var response = await _httpClient . SendAsync ( request ) ;
197
+ response = await _httpClient . SendAsync ( request ) ;
187
198
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
188
199
189
200
Assert . False ( WebScriptHostManager . InStandbyMode ) ;
@@ -226,34 +237,26 @@ public async Task StandbyMode_EndToEnd_LinuxContainer()
226
237
}
227
238
}
228
239
229
- private async Task InitializeTestHost ( string testDirName )
240
+ private void InitializeTestHost ( string testDirName )
230
241
{
231
242
var httpConfig = new HttpConfiguration ( ) ;
232
- var testRootPath = Path . Combine ( Path . GetTempPath ( ) , testDirName ) ;
233
- try
234
- {
235
- await FileUtility . DeleteDirectoryAsync ( testRootPath , true ) ;
236
- }
237
- catch
238
- {
239
- // best effort cleanup
240
- }
243
+ var uniqueTestRootPath = Path . Combine ( _testRootPath , testDirName , Guid . NewGuid ( ) . ToString ( ) ) ;
241
244
242
245
_loggerProvider = new TestLoggerProvider ( ) ;
243
246
var loggerProviderFactory = new TestLoggerProviderFactory ( _loggerProvider ) ;
244
247
_webHostSettings = new WebHostSettings
245
248
{
246
249
IsSelfHost = true ,
247
- LogPath = Path . Combine ( testRootPath , "Logs" ) ,
248
- SecretsPath = Path . Combine ( testRootPath , "Secrets" ) ,
249
- ScriptPath = Path . Combine ( testRootPath , "WWWRoot" )
250
+ LogPath = Path . Combine ( uniqueTestRootPath , "Logs" ) ,
251
+ SecretsPath = Path . Combine ( uniqueTestRootPath , "Secrets" ) ,
252
+ ScriptPath = Path . Combine ( uniqueTestRootPath , "WWWRoot" )
250
253
} ;
251
254
252
255
if ( _settingsManager . IsAppServiceEnvironment )
253
256
{
254
257
// if the test is mocking App Service environment, we need
255
258
// to also set the HOME variable
256
- Environment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteHomePath , testRootPath ) ;
259
+ Environment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteHomePath , uniqueTestRootPath ) ;
257
260
}
258
261
259
262
var loggerFactory = new LoggerFactory ( ) ;
@@ -373,12 +376,27 @@ private static async Task<Uri> CreateBlobSas(string filePath, string blobContain
373
376
public void Dispose ( )
374
377
{
375
378
ResetEnvironment ( ) ;
379
+ CleanupTestDirectory ( ) ;
380
+ }
381
+
382
+ private void CleanupTestDirectory ( )
383
+ {
384
+ var testRootPath = Path . Combine ( Path . GetTempPath ( ) , "StandbyManagerTests" ) ;
385
+ try
386
+ {
387
+ FileUtility . DeleteDirectoryAsync ( testRootPath , true ) ;
388
+ }
389
+ catch
390
+ {
391
+ // best effort cleanup
392
+ }
376
393
}
377
394
378
395
private void ResetEnvironment ( )
379
396
{
380
397
Environment . SetEnvironmentVariable ( EnvironmentSettingNames . ContainerName , string . Empty ) ;
381
398
Environment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteZipDeployment , string . Empty ) ;
399
+ Environment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteHomePath , null ) ;
382
400
WebScriptHostManager . ResetStandbyMode ( ) ;
383
401
}
384
402
}
0 commit comments