Skip to content

Commit 755ff07

Browse files
committed
Add delay in InitializationLogs_AreEmitted
1 parent 294eecd commit 755ff07

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

test/WebJobs.Script.Tests.Integration/Host/WebJobsScriptHostServiceTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ await TestHelpers.Await(() =>
153153
}
154154

155155
[Fact]
156-
public void InitializationLogs_AreEmitted()
156+
public async Task InitializationLogs_AreEmitted()
157157
{
158158
// verify startup trace logs
159159
string[] expectedPatternsWebHost =
@@ -178,9 +178,12 @@ public void InitializationLogs_AreEmitted()
178178
}
179179

180180
logs = _testHost.GetScriptHostLogMessages();
181+
await _testHost.WaitForJobHostAsync(timeout: 30);
181182
foreach (string pattern in expectedPatternsScriptHost)
182183
{
183-
Assert.True(logs.Any(p => Regex.IsMatch($"{p.Level} {p.FormattedMessage}", pattern)), $"Expected trace event {pattern} not found.{Environment.NewLine}{string.Join(Environment.NewLine, logs.OrderBy(p => p.Timestamp))}");
184+
Assert.True(
185+
logs.Any(p => Regex.IsMatch($"{p.Level} {p.FormattedMessage}", pattern)),
186+
$"Expected trace event {pattern} not found.{Environment.NewLine}Total log entries: {logs.Count}{Environment.NewLine}{string.Join(Environment.NewLine, logs.OrderBy(p => p.Timestamp))}");
184187
}
185188
}
186189

test/WebJobs.Script.Tests.Integration/TestFunctionHost.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ public async Task RestartAsync(CancellationToken cancellationToken)
267267
await _hostService.RestartHostAsync(cancellationToken);
268268
}
269269

270+
public Task WaitForJobHostAsync(int timeout = 30, CancellationToken cancellationToken = default)
271+
{
272+
if (_hostService == null)
273+
{
274+
throw new InvalidOperationException("Host service is not initialized.");
275+
}
276+
277+
return _hostService.DelayUntilHostReady(timeout).WaitAsync(cancellationToken);
278+
}
279+
270280
private void StillRunningCallback(object state)
271281
{
272282
var idProvider = JobHostServices?.GetService<IHostIdProvider>();

0 commit comments

Comments
 (0)