File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
test/WebJobs.Script.Tests.Integration/Host Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -407,12 +407,15 @@ protected virtual void Dispose(bool disposing)
407
407
408
408
public virtual void RestartHost ( )
409
409
{
410
- _restartHostEvent . Set ( ) ;
411
-
412
- // we reset the state immediately here to ensure that
410
+ // We reset the state immediately here to ensure that
413
411
// any external calls to CanInvoke will return false
414
- // immediately after the restart has been initiated
412
+ // immediately after the restart has been initiated.
413
+ // Note: this state change must be done BEFORE we set
414
+ // the event below to avoid a race condition with the
415
+ // main host lifetime loop.
415
416
State = ScriptHostState . Default ;
417
+
418
+ _restartHostEvent . Set ( ) ;
416
419
}
417
420
418
421
public virtual void Shutdown ( )
Original file line number Diff line number Diff line change @@ -288,10 +288,16 @@ public async Task EmptyHost_StartsSuccessfully()
288
288
var eventManagerMock = new Mock < IScriptEventManager > ( ) ;
289
289
ScriptHostManager hostManager = new ScriptHostManager ( config , eventManagerMock . Object ) ;
290
290
291
+ // start the host and wait for it to be running
291
292
Task runTask = Task . Run ( ( ) => hostManager . RunAndBlock ( ) ) ;
293
+ await TestHelpers . Await ( ( ) => hostManager . State == ScriptHostState . Running , timeout : 10000 ) ;
292
294
295
+ // exercise restart
296
+ hostManager . RestartHost ( ) ;
297
+ Assert . Equal ( ScriptHostState . Default , hostManager . State ) ;
293
298
await TestHelpers . Await ( ( ) => hostManager . State == ScriptHostState . Running , timeout : 10000 ) ;
294
299
300
+ // stop the host fully
295
301
hostManager . Stop ( ) ;
296
302
Assert . Equal ( ScriptHostState . Default , hostManager . State ) ;
297
303
You can’t perform that action at this time.
0 commit comments