Skip to content

Commit 1e38faf

Browse files
committed
moving a test to use in-memory logs
1 parent b1f77b7 commit 1e38faf

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,31 @@ public async Task ListenerError_LogsAndDoesNotStopHost()
2121
bool exists = await Fixture.NamespaceManager.QueueExistsAsync(queueName);
2222
Assert.False(exists, $"This test expects the queue '{queueName}' to not exist, but it does.");
2323

24-
IList<string> logs = null;
24+
IEnumerable<string> logs = null;
2525

2626
await TestHelpers.Await(() =>
2727
{
28-
logs = TestHelpers.GetFunctionLogsAsync("ListenerStartupException", false).Result;
29-
28+
logs = GetTracesForFunction("ListenerStartupException");
3029
string logToFind = "The listener for function 'Functions.ListenerStartupException' was unable to start.";
3130
return logs.Any(l => l.Contains(logToFind));
3231
});
3332

34-
TestHelpers.ClearFunctionLogs("TimerTrigger");
33+
// see how many Timer logs we've seen so far. We'll make sure we see more below.
34+
string timerLogToFind = "Timer function ran!";
35+
int timerCount = GetTracesForFunction("TimerTrigger").Count(p => p.Contains(timerLogToFind));
3536

3637
// assert that timer function is still running
3738
await TestHelpers.Await(() =>
3839
{
39-
logs = TestHelpers.GetFunctionLogsAsync("TimerTrigger", false).Result;
40-
41-
string logToFind = "Timer function ran!";
42-
return logs.Any(l => l.Contains(logToFind));
40+
int newTimerCount = GetTracesForFunction("TimerTrigger").Count(p => p.Contains(timerLogToFind));
41+
return newTimerCount > timerCount;
4342
});
4443

4544
// assert that the host is retrying to start the
4645
// listener in the background
4746
await TestHelpers.Await(() =>
4847
{
49-
logs = TestHelpers.GetHostLogsAsync().Result;
48+
logs = Fixture.TraceWriter.GetTraces().Select(p => p.Message);
5049
string logToFind = "Retrying to start listener for function 'Functions.ListenerStartupException' (Attempt 2)";
5150
return logs.Any(l => l.Contains(logToFind));
5251
});
@@ -55,6 +54,17 @@ await TestHelpers.Await(() =>
5554
Fixture.Host.Stop();
5655
}
5756

57+
private IEnumerable<string> GetTracesForFunction(string functionName)
58+
{
59+
return Fixture.TraceWriter.GetTraces()
60+
.Where(p =>
61+
{
62+
return p.Properties.TryGetValue(ScriptConstants.TracePropertyFunctionNameKey, out string name) &&
63+
name == functionName;
64+
})
65+
.Select(p => p.Message);
66+
}
67+
5868
public class TestFixture : EndToEndTestFixture
5969
{
6070
public TestFixture() : base(@"TestScripts\ListenerExceptions", "listeners")

0 commit comments

Comments
 (0)