@@ -21,7 +21,7 @@ namespace Microsoft.Azure.WebJobs.Script.Tests.Managment
21
21
public class InstanceManagerTests : IDisposable
22
22
{
23
23
private readonly TestLoggerProvider _loggerProvider ;
24
- private readonly TestEnvironment _environment ;
24
+ private readonly TestEnvironmentEx _environment ;
25
25
private readonly ScriptWebHostEnvironment _scriptWebEnvironment ;
26
26
private readonly InstanceManager _instanceManager ;
27
27
private readonly HttpClient _httpClient ;
@@ -34,11 +34,13 @@ public InstanceManagerTests()
34
34
var loggerFactory = new LoggerFactory ( ) ;
35
35
loggerFactory . AddProvider ( _loggerProvider ) ;
36
36
37
- _environment = new TestEnvironment ( ) ;
37
+ _environment = new TestEnvironmentEx ( ) ;
38
38
_scriptWebEnvironment = new ScriptWebHostEnvironment ( _environment ) ;
39
39
40
40
var optionsFactory = new TestOptionsFactory < ScriptApplicationHostOptions > ( new ScriptApplicationHostOptions ( ) ) ;
41
41
_instanceManager = new InstanceManager ( optionsFactory , _httpClient , _scriptWebEnvironment , _environment , loggerFactory . CreateLogger < InstanceManager > ( ) ) ;
42
+
43
+ InstanceManager . Reset ( ) ;
42
44
}
43
45
44
46
[ Fact ]
@@ -86,6 +88,29 @@ public async Task StartAssignment_AppliesAssignmentContext()
86
88
p => Assert . StartsWith ( "Assign called while host is not in placeholder mode" , p ) ) ;
87
89
}
88
90
91
+ [ Fact ]
92
+ public async Task StartAssignment_Failure_ExitsPlaceholderMode ( )
93
+ {
94
+ _environment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsitePlaceholderMode , "1" ) ;
95
+ var context = new HostAssignmentContext
96
+ {
97
+ Environment = new Dictionary < string , string >
98
+ {
99
+ // force the assignment to fail
100
+ { "throw" , "test" }
101
+ }
102
+ } ;
103
+ bool result = _instanceManager . StartAssignment ( context ) ;
104
+ Assert . True ( result ) ;
105
+ Assert . True ( _scriptWebEnvironment . InStandbyMode ) ;
106
+
107
+ await TestHelpers . Await ( ( ) => ! _scriptWebEnvironment . InStandbyMode , timeout : 5000 ) ;
108
+
109
+ var error = _loggerProvider . GetAllLogMessages ( ) . Where ( p => p . Level == LogLevel . Error ) . First ( ) ;
110
+ Assert . Equal ( "Assign failed" , error . FormattedMessage ) ;
111
+ Assert . Equal ( "Kaboom!" , error . Exception . Message ) ;
112
+ }
113
+
89
114
[ Fact ]
90
115
public void StartAssignment_ReturnsFalse_WhenNotInStandbyMode ( )
91
116
{
@@ -145,5 +170,17 @@ public void Dispose()
145
170
{
146
171
Environment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsitePlaceholderMode , null ) ;
147
172
}
173
+
174
+ private class TestEnvironmentEx : TestEnvironment
175
+ {
176
+ public override void SetEnvironmentVariable ( string name , string value )
177
+ {
178
+ if ( name == "throw" )
179
+ {
180
+ throw new InvalidOperationException ( "Kaboom!" ) ;
181
+ }
182
+ base . SetEnvironmentVariable ( name , value ) ;
183
+ }
184
+ }
148
185
}
149
186
}
0 commit comments