@@ -21,32 +21,31 @@ public async Task ListenerError_LogsAndDoesNotStopHost()
21
21
bool exists = await Fixture . NamespaceManager . QueueExistsAsync ( queueName ) ;
22
22
Assert . False ( exists , $ "This test expects the queue '{ queueName } ' to not exist, but it does.") ;
23
23
24
- IList < string > logs = null ;
24
+ IEnumerable < string > logs = null ;
25
25
26
26
await TestHelpers . Await ( ( ) =>
27
27
{
28
- logs = TestHelpers . GetFunctionLogsAsync ( "ListenerStartupException" , false ) . Result ;
29
-
28
+ logs = GetTracesForFunction ( "ListenerStartupException" ) ;
30
29
string logToFind = "The listener for function 'Functions.ListenerStartupException' was unable to start." ;
31
30
return logs . Any ( l => l . Contains ( logToFind ) ) ;
32
31
} ) ;
33
32
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 ) ) ;
35
36
36
37
// assert that timer function is still running
37
38
await TestHelpers . Await ( ( ) =>
38
39
{
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 ;
43
42
} ) ;
44
43
45
44
// assert that the host is retrying to start the
46
45
// listener in the background
47
46
await TestHelpers . Await ( ( ) =>
48
47
{
49
- logs = TestHelpers . GetHostLogsAsync ( ) . Result ;
48
+ logs = Fixture . TraceWriter . GetTraces ( ) . Select ( p => p . Message ) ;
50
49
string logToFind = "Retrying to start listener for function 'Functions.ListenerStartupException' (Attempt 2)" ;
51
50
return logs . Any ( l => l . Contains ( logToFind ) ) ;
52
51
} ) ;
@@ -55,6 +54,17 @@ await TestHelpers.Await(() =>
55
54
Fixture . Host . Stop ( ) ;
56
55
}
57
56
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
+
58
68
public class TestFixture : EndToEndTestFixture
59
69
{
60
70
public TestFixture ( ) : base ( @"TestScripts\ListenerExceptions" , "listeners" )
0 commit comments