3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
- using System . Collections . ObjectModel ;
7
6
using System . Diagnostics ;
8
7
using System . IO ;
9
8
using System . Linq ;
@@ -31,9 +30,6 @@ public class WebScriptHostManagerTests : IClassFixture<WebScriptHostManagerTests
31
30
private readonly TempDirectory _secretsDirectory = new TempDirectory ( ) ;
32
31
private WebScriptHostManagerTests . Fixture _fixture ;
33
32
34
- // Some tests need their own manager that differs from the fixture.
35
- private WebScriptHostManager _manager ;
36
-
37
33
public WebScriptHostManagerTests ( WebScriptHostManagerTests . Fixture fixture )
38
34
{
39
35
_fixture = fixture ;
@@ -53,11 +49,15 @@ public async Task FunctionInvoke_SystemTraceEventsAreEmitted()
53
49
} ;
54
50
await host . CallAsync ( "ManualTrigger" , parameters ) ;
55
51
52
+ // it's possible that the TimerTrigger fires during this so filter them out.
53
+
54
+ string [ ] events = _fixture . EventGenerator . Events . Where ( e => ! e . Contains ( "TimerTrigger" ) ) . ToArray ( ) ;
55
+ Assert . True ( events . Length == 4 , $ "Expected 4 events. Actual: { events . Length } . Actual events: { Environment . NewLine } { string . Join ( Environment . NewLine , events ) } ") ;
56
56
Assert . Equal ( 4 , _fixture . EventGenerator . Events . Count ) ;
57
- Assert . True ( _fixture . EventGenerator . Events [ 0 ] . StartsWith ( "Info WebJobs.Execution Executing 'Functions.ManualTrigger' (Reason='This function was programmatically called via the host APIs.', Id=" ) ) ;
58
- Assert . True ( _fixture . EventGenerator . Events [ 1 ] . StartsWith ( "Info ManualTrigger Function started (Id=" ) ) ;
59
- Assert . True ( _fixture . EventGenerator . Events [ 2 ] . StartsWith ( "Info ManualTrigger Function completed (Success, Id=" ) ) ;
60
- Assert . True ( _fixture . EventGenerator . Events [ 3 ] . StartsWith ( "Info WebJobs.Execution Executed 'Functions.ManualTrigger' (Succeeded, Id=" ) ) ;
57
+ Assert . StartsWith ( "Info WebJobs.Execution Executing 'Functions.ManualTrigger' (Reason='This function was programmatically called via the host APIs.', Id=" , events [ 0 ] ) ;
58
+ Assert . StartsWith ( "Info ManualTrigger Function started (Id=" , events [ 1 ] ) ;
59
+ Assert . StartsWith ( "Info ManualTrigger Function completed (Success, Id=" , events [ 2 ] ) ;
60
+ Assert . StartsWith ( "Info WebJobs.Execution Executed 'Functions.ManualTrigger' (Succeeded, Id=" , events [ 3 ] ) ;
61
61
62
62
// make sure the user log wasn't traced
63
63
Assert . False ( _fixture . EventGenerator . Events . Any ( p => p . Contains ( "ManualTrigger function invoked!" ) ) ) ;
@@ -118,7 +118,7 @@ public async Task EmptyHost_StartsSuccessfully()
118
118
webHostSettings . SecretsPath = _secretsDirectory . Path ;
119
119
var mockEventManager = new Mock < IScriptEventManager > ( ) ;
120
120
121
- ScriptHostManager hostManager = new WebScriptHostManager ( config , new TestSecretManagerFactory ( secretManager ) , mockEventManager . Object , _settingsManager , webHostSettings ) ;
121
+ ScriptHostManager hostManager = new WebScriptHostManager ( config , new TestSecretManagerFactory ( secretManager ) , mockEventManager . Object , _settingsManager , webHostSettings ) ;
122
122
123
123
Task runTask = Task . Run ( ( ) => hostManager . RunAndBlock ( ) ) ;
124
124
@@ -186,33 +186,6 @@ await TestHelpers.Await(() =>
186
186
Assert . Equal ( typeof ( SystemTraceWriter ) , config . TraceWriter . GetType ( ) ) ;
187
187
}
188
188
189
- [ Fact ]
190
- public async Task OnTimeoutException_IgnoreToken_StopsManager ( )
191
- {
192
- var trace = new TestTraceWriter ( TraceLevel . Info ) ;
193
-
194
- await RunTimeoutExceptionTest ( trace , handleCancellation : false ) ;
195
-
196
- await TestHelpers . Await ( ( ) => ! ( _manager . State == ScriptHostState . Running ) ) ;
197
- Assert . DoesNotContain ( trace . Traces , t => t . Message . StartsWith ( "Done" ) ) ;
198
- Assert . Contains ( trace . Traces , t => t . Message . StartsWith ( "Timeout value of 00:00:03 exceeded by function 'Functions.TimeoutToken' (Id: " ) ) ;
199
- Assert . Contains ( trace . Traces , t => t . Message == "A function timeout has occurred. Host is shutting down." ) ;
200
- }
201
-
202
- [ Fact ]
203
- public async Task OnTimeoutException_UsesToken_ManagerKeepsRunning ( )
204
- {
205
- var trace = new TestTraceWriter ( TraceLevel . Info ) ;
206
-
207
- await RunTimeoutExceptionTest ( trace , handleCancellation : true ) ;
208
-
209
- // wait a few seconds to make sure the manager doesn't die
210
- await Assert . ThrowsAsync < ApplicationException > ( ( ) => TestHelpers . Await ( ( ) => ! ( _manager . State == ScriptHostState . Running ) , timeout : 3000 ) ) ;
211
- Assert . Contains ( trace . Traces , t => t . Message . StartsWith ( "Done" ) ) ;
212
- Assert . Contains ( trace . Traces , t => t . Message . StartsWith ( "Timeout value of 00:00:03 exceeded by function 'Functions.TimeoutToken' (Id: " ) ) ;
213
- Assert . DoesNotContain ( trace . Traces , t => t . Message == "A function timeout has occurred. Host is shutting down." ) ;
214
- }
215
-
216
189
[ Fact ]
217
190
public void AddRouteDataToRequest_DoesNotAddRequestProperty_WhenRouteDataNull ( )
218
191
{
@@ -249,50 +222,8 @@ public void AddRouteDataToRequest_AddsRequestProperty_WhenRouteDataNotNull()
249
222
Assert . Equal ( result [ "p4" ] , null ) ;
250
223
}
251
224
252
- private async Task RunTimeoutExceptionTest ( TraceWriter trace , bool handleCancellation )
253
- {
254
- TimeSpan gracePeriod = TimeSpan . FromMilliseconds ( 5000 ) ;
255
- _manager = await CreateAndStartWebScriptHostManager ( trace ) ;
256
-
257
- string scenarioName = handleCancellation ? "useToken" : "ignoreToken" ;
258
-
259
- var args = new Dictionary < string , object >
260
- {
261
- { "input" , scenarioName }
262
- } ;
263
-
264
- await Assert . ThrowsAsync < FunctionTimeoutException > ( ( ) => _manager . Instance . CallAsync ( "TimeoutToken" , args ) ) ;
265
- }
266
-
267
- private async Task < WebScriptHostManager > CreateAndStartWebScriptHostManager ( TraceWriter traceWriter )
268
- {
269
- var functions = new Collection < string > { "TimeoutToken" } ;
270
-
271
- ScriptHostConfiguration config = new ScriptHostConfiguration ( )
272
- {
273
- RootScriptPath = $@ "TestScripts\CSharp",
274
- TraceWriter = traceWriter ,
275
- FileLoggingMode = FileLoggingMode . Always ,
276
- Functions = functions ,
277
- FunctionTimeout = TimeSpan . FromSeconds ( 3 )
278
- } ;
279
-
280
- var mockEventManager = new Mock < IScriptEventManager > ( ) ;
281
- var manager = new WebScriptHostManager ( config , new TestSecretManagerFactory ( ) , mockEventManager . Object , _settingsManager , new WebHostSettings { SecretsPath = _secretsDirectory . Path } ) ;
282
- Task task = Task . Run ( ( ) => { manager . RunAndBlock ( ) ; } ) ;
283
- await TestHelpers . Await ( ( ) => manager . State == ScriptHostState . Running ) ;
284
-
285
- return manager ;
286
- }
287
-
288
225
public void Dispose ( )
289
226
{
290
- if ( _manager != null )
291
- {
292
- _manager . Stop ( ) ;
293
- _manager . Dispose ( ) ;
294
- }
295
-
296
227
_secretsDirectory . Dispose ( ) ;
297
228
}
298
229
0 commit comments