10
10
using System . Threading . Tasks ;
11
11
using Microsoft . Azure . WebJobs . Script . Description ;
12
12
using Microsoft . Azure . WebJobs . Script . Diagnostics ;
13
+ using Microsoft . Azure . WebJobs . Script . Tests . Workers . Rpc ;
13
14
using Microsoft . Azure . WebJobs . Script . Workers ;
14
15
using Microsoft . Azure . WebJobs . Script . Workers . Rpc ;
15
16
using Microsoft . Extensions . Logging ;
16
17
using Microsoft . Extensions . Logging . Abstractions ;
18
+ using Microsoft . Extensions . Options ;
19
+ using Microsoft . WebJobs . Script . Tests ;
17
20
using Moq ;
18
21
using Xunit ;
19
22
20
23
namespace Microsoft . Azure . WebJobs . Script . Tests
21
24
{
22
- public class WorkerFunctionMetadataProviderTests
25
+ public class AggregateFunctionMetadataProviderTests
23
26
{
24
27
private readonly TestLogger _logger ;
25
28
private AggregateFunctionMetadataProvider _aggregateFunctionMetadataProvider ;
26
29
private Mock < IFunctionInvocationDispatcher > _mockRpcFunctionInvocationDispatcher ;
27
30
private Mock < IFunctionMetadataProvider > _mockFunctionMetadataProvider ;
28
31
29
- public WorkerFunctionMetadataProviderTests ( )
32
+ public AggregateFunctionMetadataProviderTests ( )
30
33
{
31
- _logger = new TestLogger ( "WorkerFunctionMetadataProviderTests " ) ;
34
+ _logger = new TestLogger ( "AggregateFunctionMetadataProviderTests " ) ;
32
35
_mockRpcFunctionInvocationDispatcher = new Mock < IFunctionInvocationDispatcher > ( ) ;
33
36
_mockFunctionMetadataProvider = new Mock < IFunctionMetadataProvider > ( ) ;
34
37
}
@@ -158,6 +161,8 @@ public void GetFunctionMetadataAsync_WorkerIndexing_HostFallback()
158
161
159
162
var workerConfigs = TestHelpers . GetTestWorkerConfigs ( ) . ToImmutableArray ( ) ;
160
163
workerConfigs . ToList ( ) . ForEach ( config => config . Description . WorkerIndexing = "true" ) ;
164
+ var scriptjobhostoptions = new ScriptJobHostOptions ( ) ;
165
+ scriptjobhostoptions . RootScriptPath = Path . Combine ( Environment . CurrentDirectory , @".." , ".." , ".." , ".." , ".." , "sample" , "node" ) ;
161
166
162
167
var environment = SystemEnvironment . Instance ;
163
168
environment . SetEnvironmentVariable ( EnvironmentSettingNames . FunctionWorkerRuntime , "node" ) ;
@@ -168,7 +173,7 @@ public void GetFunctionMetadataAsync_WorkerIndexing_HostFallback()
168
173
_mockRpcFunctionInvocationDispatcher . Setup ( m => m . FinishInitialization ( functionMetadataCollection , default ) ) . Returns ( Task . FromResult ( 0 ) ) ;
169
174
_mockFunctionMetadataProvider . Setup ( m => m . GetFunctionMetadataAsync ( workerConfigs , environment , false ) ) . Returns ( Task . FromResult ( functionMetadataCollection . ToImmutableArray ( ) ) ) ;
170
175
171
- _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider ( _logger , _mockRpcFunctionInvocationDispatcher . Object , _mockFunctionMetadataProvider . Object ) ;
176
+ _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider ( _logger , _mockRpcFunctionInvocationDispatcher . Object , _mockFunctionMetadataProvider . Object , new OptionsWrapper < ScriptJobHostOptions > ( scriptjobhostoptions ) ) ;
172
177
173
178
// Act
174
179
var functions = _aggregateFunctionMetadataProvider . GetFunctionMetadataAsync ( workerConfigs , environment , false ) . GetAwaiter ( ) . GetResult ( ) ;
@@ -193,13 +198,15 @@ public void GetFunctionMetadataAsync_HostIndexing()
193
198
var workerConfigs = TestHelpers . GetTestWorkerConfigs ( ) . ToImmutableArray ( ) ;
194
199
var environment = SystemEnvironment . Instance ;
195
200
environment . SetEnvironmentVariable ( EnvironmentSettingNames . FunctionWorkerRuntime , "node" ) ;
201
+ var scriptjobhostoptions = new ScriptJobHostOptions ( ) ;
202
+ scriptjobhostoptions . RootScriptPath = Path . Combine ( Environment . CurrentDirectory , @".." , ".." , ".." , ".." , ".." , "sample" , "node" ) ;
196
203
197
204
_mockRpcFunctionInvocationDispatcher . Setup ( m => m . InitializeAsync ( functionMetadataCollection , default ) ) . Returns ( Task . FromResult ( 0 ) ) ;
198
205
_mockRpcFunctionInvocationDispatcher . Setup ( m => m . GetWorkerMetadata ( ) ) . Returns ( Task . FromResult ( rawFunctionMetadataCollection ) ) ;
199
206
_mockRpcFunctionInvocationDispatcher . Setup ( m => m . FinishInitialization ( functionMetadataCollection , default ) ) . Returns ( Task . FromResult ( 0 ) ) ;
200
207
_mockFunctionMetadataProvider . Setup ( m => m . GetFunctionMetadataAsync ( workerConfigs , environment , false ) ) . Returns ( Task . FromResult ( functionMetadataCollection . ToImmutableArray ( ) ) ) ;
201
208
202
- _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider ( _logger , _mockRpcFunctionInvocationDispatcher . Object , _mockFunctionMetadataProvider . Object ) ;
209
+ _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider ( _logger , _mockRpcFunctionInvocationDispatcher . Object , _mockFunctionMetadataProvider . Object , new OptionsWrapper < ScriptJobHostOptions > ( scriptjobhostoptions ) ) ;
203
210
204
211
//Act
205
212
var functions = _aggregateFunctionMetadataProvider . GetFunctionMetadataAsync ( workerConfigs , environment , false ) . GetAwaiter ( ) . GetResult ( ) ;
@@ -210,6 +217,17 @@ public void GetFunctionMetadataAsync_HostIndexing()
210
217
Assert . False ( functionLoadLogs . Any ( ) ) ;
211
218
}
212
219
220
+ [ Fact ]
221
+ public void ValidateFunctionAppFormat_InputMixedApp ( )
222
+ {
223
+ _logger . ClearLogMessages ( ) ;
224
+ string scriptPath = Path . Combine ( Environment . CurrentDirectory , @".." , ".." , ".." , ".." , ".." , "sample" , "node" ) ;
225
+ AggregateFunctionMetadataProvider . ValidateFunctionAppFormat ( scriptPath , _logger ) ;
226
+ var traces = _logger . GetLogMessages ( ) ;
227
+ var functionLoadLogs = traces . Where ( m => m . FormattedMessage . Contains ( "Detected mixed function app. Some functions may not be indexed" ) ) ;
228
+ Assert . True ( functionLoadLogs . Any ( ) ) ;
229
+ }
230
+
213
231
[ Fact ]
214
232
public void GetFunctionMetadataAsync_WorkerIndexing_NoHostFallback ( )
215
233
{
@@ -221,6 +239,8 @@ public void GetFunctionMetadataAsync_WorkerIndexing_NoHostFallback()
221
239
222
240
var workerConfigs = TestHelpers . GetTestWorkerConfigs ( ) . ToImmutableArray ( ) ;
223
241
workerConfigs . ToList ( ) . ForEach ( config => config . Description . WorkerIndexing = "true" ) ;
242
+ var scriptjobhostoptions = new ScriptJobHostOptions ( ) ;
243
+ scriptjobhostoptions . RootScriptPath = Path . Combine ( Environment . CurrentDirectory , @".." , ".." , ".." , ".." , ".." , "sample" , "node" ) ;
224
244
225
245
var environment = SystemEnvironment . Instance ;
226
246
environment . SetEnvironmentVariable ( EnvironmentSettingNames . FunctionWorkerRuntime , "node" ) ;
@@ -232,7 +252,7 @@ public void GetFunctionMetadataAsync_WorkerIndexing_NoHostFallback()
232
252
_mockRpcFunctionInvocationDispatcher . Setup ( m => m . FinishInitialization ( functionMetadataCollection , default ) ) . Returns ( Task . FromResult ( 0 ) ) ;
233
253
_mockFunctionMetadataProvider . Setup ( m => m . GetFunctionMetadataAsync ( workerConfigs , environment , false ) ) . Returns ( Task . FromResult ( functionMetadataCollection . ToImmutableArray ( ) ) ) ;
234
254
235
- _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider ( _logger , _mockRpcFunctionInvocationDispatcher . Object , _mockFunctionMetadataProvider . Object ) ;
255
+ _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider ( _logger , _mockRpcFunctionInvocationDispatcher . Object , _mockFunctionMetadataProvider . Object , new OptionsWrapper < ScriptJobHostOptions > ( scriptjobhostoptions ) ) ;
236
256
237
257
// Act
238
258
var functions = _aggregateFunctionMetadataProvider . GetFunctionMetadataAsync ( workerConfigs , environment , false ) . GetAwaiter ( ) . GetResult ( ) ;
@@ -244,6 +264,47 @@ public void GetFunctionMetadataAsync_WorkerIndexing_NoHostFallback()
244
264
Assert . True ( functions . Count ( ) == 0 ) ;
245
265
}
246
266
267
+ [ Fact ]
268
+ public void GetFunctionMetadataAsync_InputMixedApp ( )
269
+ {
270
+ // Arrange
271
+ _logger . ClearLogMessages ( ) ;
272
+
273
+ IEnumerable < RawFunctionMetadata > rawFunctionMetadataCollection = new List < RawFunctionMetadata > ( ) ;
274
+ var functionMetadataCollection = new List < FunctionMetadata > ( ) ;
275
+ functionMetadataCollection . Add ( GetTestFunctionMetadata ( ) ) ;
276
+
277
+ var workerConfigs = TestHelpers . GetTestWorkerConfigs ( ) . ToImmutableArray ( ) ;
278
+ workerConfigs . ToList ( ) . ForEach ( config => config . Description . WorkerIndexing = "true" ) ;
279
+ var scriptjobhostoptions = new ScriptJobHostOptions ( ) ;
280
+ scriptjobhostoptions . RootScriptPath = Path . Combine ( Environment . CurrentDirectory , @".." , ".." , ".." , ".." , ".." , "sample" , "node" ) ;
281
+
282
+ var environment = SystemEnvironment . Instance ;
283
+ environment . SetEnvironmentVariable ( EnvironmentSettingNames . FunctionWorkerRuntime , "node" ) ;
284
+ environment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebJobsFeatureFlags , "EnableWorkerIndexing" ) ;
285
+
286
+ _mockRpcFunctionInvocationDispatcher . Setup ( m => m . InitializeAsync ( functionMetadataCollection , default ) ) . Returns ( Task . FromResult ( 0 ) ) ;
287
+ _mockRpcFunctionInvocationDispatcher . Setup ( m => m . GetWorkerMetadata ( ) ) . Returns ( Task . FromResult ( rawFunctionMetadataCollection ) ) ;
288
+
289
+ _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider (
290
+ _logger ,
291
+ _mockRpcFunctionInvocationDispatcher . Object ,
292
+ _mockFunctionMetadataProvider . Object ,
293
+ new OptionsWrapper < ScriptJobHostOptions > ( scriptjobhostoptions ) ) ;
294
+
295
+ // Act
296
+ var functions = _aggregateFunctionMetadataProvider . GetFunctionMetadataAsync ( workerConfigs , environment , false ) . GetAwaiter ( ) . GetResult ( ) ;
297
+
298
+ // Assert
299
+ string expectedLog = "Detected mixed function app. Some functions may not be indexed" ;
300
+ var traces = _logger . GetLogMessages ( ) ;
301
+ Assert . False ( traces . Where ( m => m . FormattedMessage . Contains ( expectedLog ) ) . Any ( ) ) ;
302
+
303
+ Task . Delay ( TimeSpan . FromSeconds ( 65 ) ) . Wait ( ) ;
304
+ traces = _logger . GetLogMessages ( ) ;
305
+ Assert . True ( traces . Where ( m => m . FormattedMessage . Contains ( expectedLog ) ) . Any ( ) ) ;
306
+ }
307
+
247
308
private static RawFunctionMetadata GetTestRawFunctionMetadata ( bool useDefaultMetadataIndexing )
248
309
{
249
310
return new RawFunctionMetadata ( )
0 commit comments