3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Linq ;
7
+ using System . Reflection ;
8
+ using Microsoft . Azure . WebJobs . Host . Loggers ;
6
9
using Microsoft . Azure . WebJobs . Logging ;
7
10
using Microsoft . Azure . WebJobs . Script . Configuration ;
11
+ using Microsoft . Azure . WebJobs . Script . WebHost . Diagnostics ;
8
12
using Microsoft . Extensions . Configuration ;
9
13
using Microsoft . Extensions . DependencyInjection ;
10
14
using Microsoft . Extensions . Hosting ;
@@ -16,17 +20,42 @@ namespace Microsoft.Azure.WebJobs.Script.Tests.Configuration
16
20
{
17
21
public class AggregatorConfigurationTests
18
22
{
23
+ private static readonly string AggregatorPath = ConfigurationPath . Combine ( ConfigurationSectionNames . JobHost , ConfigurationSectionNames . Aggregator ) ;
24
+
25
+ [ Fact ]
26
+ public void Aggregator_Registered_ByDefault ( )
27
+ {
28
+ IHost host = new HostBuilder ( )
29
+ . ConfigureDefaultTestWebScriptHost ( )
30
+ . Build ( ) ;
31
+
32
+ // Make sure there are two providers registered, and that one has a type with
33
+ // "FunctionResultAggregatorProvider" (since it is internal to WebJobs)
34
+ var eventCollectorProviders = host . Services . GetServices < IEventCollectorProvider > ( ) ;
35
+ Assert . Equal ( 2 , eventCollectorProviders . Count ( ) ) ;
36
+ Assert . Single ( eventCollectorProviders . OfType < FunctionInstanceLogCollectorProvider > ( ) ) ;
37
+ Assert . Single ( eventCollectorProviders . Where ( p => p . GetType ( ) . Name . Contains ( "FunctionResultAggregatorProvider" ) ) ) ;
38
+
39
+ // Also make sure that when requesting the collectors, we end up with a composite that
40
+ // includes both of the collectors above. This prevents any overriding of the IEventCollectorFactory
41
+ var eventLogger = host . Services . GetServices < IAsyncCollector < FunctionInstanceLogEntry > > ( ) . Single ( ) ;
42
+ var field = eventLogger . GetType ( ) . GetField ( "_collectors" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
43
+ var collectors = ( IEnumerable < IAsyncCollector < FunctionInstanceLogEntry > > ) field . GetValue ( eventLogger ) ;
44
+ Assert . Equal ( 2 , collectors . Count ( ) ) ;
45
+ Assert . Single ( collectors . OfType < FunctionInstanceLogger > ( ) ) ;
46
+ Assert . Single ( collectors . Where ( p => p . GetType ( ) . Name . Contains ( "FunctionResultAggregator" ) ) ) ;
47
+ }
48
+
19
49
[ Fact ]
20
50
public void Configuration_BindsTo_AggregatorOptions ( )
21
51
{
22
- string aggregatorPath = ConfigurationPath . Combine ( ConfigurationSectionNames . JobHost , ConfigurationSectionNames . Aggregator ) ;
23
52
IHost host = new HostBuilder ( )
24
53
. ConfigureAppConfiguration ( c =>
25
54
{
26
55
c . AddInMemoryCollection ( new Dictionary < string , string >
27
56
{
28
- { ConfigurationPath . Combine ( aggregatorPath , "BatchSize" ) , "33" } ,
29
- { ConfigurationPath . Combine ( aggregatorPath , "FlushTimeout" ) , "00:00:33" }
57
+ { ConfigurationPath . Combine ( AggregatorPath , "BatchSize" ) , "33" } ,
58
+ { ConfigurationPath . Combine ( AggregatorPath , "FlushTimeout" ) , "00:00:33" }
30
59
} ) ;
31
60
} )
32
61
. ConfigureDefaultTestWebScriptHost ( )
0 commit comments