Skip to content

Commit 362d8c6

Browse files
Wait for Function host to fully start in Integration tests (#222)
* Wait for function host to fully start * Remove unused * Add logging * Use different string * Remove duplicate log
1 parent 25c84ca commit 362d8c6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test/Integration/IntegrationTestBase.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using System.Reflection;
1212
using System.Runtime.InteropServices;
1313
using System.Text;
14-
using System.Threading;
1514
using System.Threading.Tasks;
1615
using Xunit;
1716
using Xunit.Abstractions;
@@ -189,7 +188,19 @@ protected void StartFunctionHost(string functionName, bool useTestFolder = false
189188
this.FunctionHost.BeginOutputReadLine();
190189
this.FunctionHost.BeginErrorReadLine();
191190

192-
Thread.Sleep(10000); // This is just to give some time to func host to start, maybe there's a better way to do this (check if port's open?)
191+
var taskCompletionSource = new TaskCompletionSource<bool>();
192+
this.FunctionHost.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
193+
{
194+
// This string is printed after the function host is started up - use this to ensure that we wait long enough
195+
// since sometimes the host can take a little while to fully start up
196+
if (e.Data.Contains("Job host started"))
197+
{
198+
taskCompletionSource.SetResult(true);
199+
}
200+
};
201+
this.TestOutput.WriteLine($"Waiting for Azure Function host to start...");
202+
taskCompletionSource.Task.Wait();
203+
this.TestOutput.WriteLine($"Azure Function host started!");
193204
}
194205

195206
private static string GetFunctionsCoreToolsPath()

0 commit comments

Comments
 (0)