@@ -58,11 +58,11 @@ public async Task UpdateFileAndRestart()
5858 // Background task to run while the main thread is pumping events at RunAndBlock().
5959 Thread t = new Thread ( _ =>
6060 {
61- // don't start until the manager is running
62- TestHelpers . Await ( ( ) => manager . State == ScriptHostState . Running ) . Wait ( ) ;
63-
6461 try
6562 {
63+ // don't start until the manager is running
64+ TestHelpers . Await ( ( ) => manager . State == ScriptHostState . Running ) . Wait ( ) ;
65+
6666 // Wait for initial execution.
6767 TestHelpers . Await ( ( ) =>
6868 {
@@ -116,6 +116,15 @@ public async Task RenameFunctionAndRestart()
116116 var newDirectory = Path . Combine ( Directory . GetCurrentDirectory ( ) , "TestScripts/Node/MovedTrigger" ) ;
117117
118118 CancellationTokenSource cts = new CancellationTokenSource ( ) ;
119+
120+ // Don't wait forever
121+ bool timeout = false ;
122+ Task ignore = Task . Delay ( TimeSpan . FromMinutes ( 3 ) ) . ContinueWith ( ( t ) =>
123+ {
124+ timeout = true ;
125+ cts . Cancel ( ) ;
126+ } ) ;
127+
119128 var fixture = new NodeEndToEndTests . TestFixture ( ) ;
120129 await fixture . Host . StopAsync ( ) ;
121130 var config = fixture . Host . ScriptConfig ;
@@ -139,11 +148,11 @@ public async Task RenameFunctionAndRestart()
139148 // Background task to run while the main thread is pumping events at RunAndBlock().
140149 Thread t = new Thread ( _ =>
141150 {
142- // don't start until the manager is running
143- TestHelpers . Await ( ( ) => manager . State == ScriptHostState . Running ) . Wait ( ) ;
144-
145151 try
146152 {
153+ // don't start until the manager is running
154+ TestHelpers . Await ( ( ) => manager . State == ScriptHostState . Running ) . Wait ( ) ;
155+
147156 // Wait for initial execution.
148157 TestHelpers . Await ( ( ) =>
149158 {
@@ -164,7 +173,7 @@ public async Task RenameFunctionAndRestart()
164173 // rename directory & delete old blob
165174 Directory . Move ( oldDirectory , newDirectory ) ;
166175
167- resetEvent . Wait ( TimeSpan . FromSeconds ( 10 ) ) ;
176+ Assert . True ( resetEvent . Wait ( TimeSpan . FromSeconds ( 10 ) ) , "Timeout waiting for 'RestartHost' to be called." ) ;
168177
169178 blob . Delete ( ) ;
170179
@@ -201,12 +210,14 @@ public async Task RenameFunctionAndRestart()
201210
202211 cts . Cancel ( ) ;
203212 } ) ;
213+
204214 t . Start ( ) ;
205215
206216 manager . RunAndBlock ( cts . Token ) ;
207217
208- t . Join ( ) ;
218+ Assert . True ( t . Join ( TimeSpan . FromSeconds ( 10 ) ) , "Thread join timed out." ) ;
209219
220+ Assert . False ( timeout , "The test timed out and was canceled." ) ;
210221 Assert . True ( exception == null , exception ? . SourceException ? . ToString ( ) ) ;
211222 Assert . True ( moveException == null , "Failed to move function back to original directory: " + moveException ? . SourceException ? . ToString ( ) ) ;
212223 }
0 commit comments