@@ -308,10 +308,10 @@ public async Task AddWorkerIfNeeded_Returns_Expected(WorkerConcurrencyOptions op
308
308
LatencyHistory = latencies2 . Select ( x => TimeSpan . FromMilliseconds ( x ) )
309
309
} ) ;
310
310
311
- WorkerConcurrencyManager concurrancyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , _testEnvironment , Options . Create ( options ) ,
311
+ WorkerConcurrencyManager concurrencyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , _testEnvironment , Options . Create ( options ) ,
312
312
_functionsHostingConfigurations , _applicationLifetime , _loggerFactory ) ;
313
- await concurrancyManager . StartAsync ( CancellationToken . None ) ;
314
- bool value = concurrancyManager . NewWorkerIsRequired ( workerStatuses , elapsedFromLastAdding ) ;
313
+ await concurrencyManager . StartAsync ( CancellationToken . None ) ;
314
+ bool value = concurrencyManager . NewWorkerIsRequired ( workerStatuses , elapsedFromLastAdding ) ;
315
315
316
316
Assert . Equal ( value , expected ) ;
317
317
}
@@ -323,9 +323,9 @@ public async Task StartAsync_DoesNotGetDispatcher(string workerRuntime)
323
323
{
324
324
_testEnvironment . SetEnvironmentVariable ( EnvironmentSettingNames . FunctionWorkerRuntime , workerRuntime ) ;
325
325
Mock < IFunctionInvocationDispatcherFactory > functionInvocationDispatcherFactory = new Mock < IFunctionInvocationDispatcherFactory > ( MockBehavior . Strict ) ;
326
- WorkerConcurrencyManager concurrancyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , _testEnvironment , Options . Create ( new WorkerConcurrencyOptions ( ) ) ,
326
+ WorkerConcurrencyManager concurrencyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , _testEnvironment , Options . Create ( new WorkerConcurrencyOptions ( ) ) ,
327
327
_functionsHostingConfigurations , _applicationLifetime , _loggerFactory ) ;
328
- await concurrancyManager . StartAsync ( CancellationToken . None ) ;
328
+ await concurrencyManager . StartAsync ( CancellationToken . None ) ;
329
329
}
330
330
331
331
[ Theory ]
@@ -339,9 +339,9 @@ public async Task StartAsync_GetsDispatcher(string workerRuntime)
339
339
Mock < IFunctionInvocationDispatcherFactory > functionInvocationDispatcherFactory = new Mock < IFunctionInvocationDispatcherFactory > ( MockBehavior . Strict ) ;
340
340
functionInvocationDispatcherFactory . Setup ( x => x . GetFunctionDispatcher ( ) ) . Returns ( functionInvocationDispatcher . Object ) ;
341
341
342
- WorkerConcurrencyManager concurrancyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , _testEnvironment , Options . Create ( new WorkerConcurrencyOptions ( ) ) ,
342
+ WorkerConcurrencyManager concurrencyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , _testEnvironment , Options . Create ( new WorkerConcurrencyOptions ( ) ) ,
343
343
_functionsHostingConfigurations , _applicationLifetime , _loggerFactory ) ;
344
- await concurrancyManager . StartAsync ( CancellationToken . None ) ;
344
+ await concurrencyManager . StartAsync ( CancellationToken . None ) ;
345
345
}
346
346
347
347
[ Fact ]
@@ -356,10 +356,10 @@ public async Task ActivateWorkerConcurency_FunctionsHostingConfiguration_WorkAsE
356
356
conf . Setup ( x => x . FunctionsWorkerDynamicConcurrencyEnabled ) . Returns ( true ) ;
357
357
WorkerConcurrencyOptions options = new WorkerConcurrencyOptions ( ) ;
358
358
359
- WorkerConcurrencyManager concurrancyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , testEnvironment , Options . Create ( options ) , conf . Object ,
359
+ WorkerConcurrencyManager concurrencyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , testEnvironment , Options . Create ( options ) , conf . Object ,
360
360
_applicationLifetime , _loggerFactory ) ;
361
- concurrancyManager . ActivationTimerInterval = TimeSpan . FromMilliseconds ( 100 ) ;
362
- await concurrancyManager . StartAsync ( CancellationToken . None ) ;
361
+ concurrencyManager . ActivationTimerInterval = TimeSpan . FromMilliseconds ( 100 ) ;
362
+ await concurrencyManager . StartAsync ( CancellationToken . None ) ;
363
363
await TestHelpers . Await ( ( ) => _loggerProvider . GetAllLogMessages ( ) . SingleOrDefault ( x => x . FormattedMessage . StartsWith ( "Dynamic worker concurrency monitoring was started by activation timer." ) ) != null , timeout : 1000 , pollingInterval : 100 ) ;
364
364
conf . Setup ( x => x . FunctionsWorkerDynamicConcurrencyEnabled ) . Returns ( false ) ;
365
365
await TestHelpers . Await ( ( ) => _loggerProvider . GetAllLogMessages ( ) . SingleOrDefault ( x => x . FormattedMessage . StartsWith ( "Dynamic worker concurrency monitoring is disabled after activation. Shutting down Functions Host." ) ) != null , timeout : 1000 , pollingInterval : 100 ) ;
@@ -377,14 +377,55 @@ public void IsEnoughMemory_WorkAsExpected(long availableMemory, long hostProcess
377
377
Mock < IFunctionsHostingConfiguration > conf = new Mock < IFunctionsHostingConfiguration > ( ) ;
378
378
WorkerConcurrencyOptions options = new WorkerConcurrencyOptions ( ) ;
379
379
380
- WorkerConcurrencyManager concurrancyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , testEnvironment ,
380
+ WorkerConcurrencyManager concurrencyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , testEnvironment ,
381
381
Options . Create ( options ) , conf . Object , _applicationLifetime , _loggerFactory ) ;
382
382
383
- Assert . True ( concurrancyManager . IsEnoughMemoryToScale ( hostProcessSize , languageWorkerSizes , availableMemory ) == result ) ;
383
+ Assert . True ( concurrencyManager . IsEnoughMemoryToScale ( hostProcessSize , languageWorkerSizes , availableMemory ) == result ) ;
384
384
if ( ! result )
385
385
{
386
386
Assert . Contains ( _loggerProvider . GetAllLogMessages ( ) . Select ( x => x . FormattedMessage ) , x => x . StartsWith ( "Starting new language worker canceled:" ) ) ;
387
387
}
388
388
}
389
+
390
+ [ Theory ]
391
+ [ InlineData ( 4 , new bool [ ] { true , true , true } , true ) ]
392
+ [ InlineData ( 3 , new bool [ ] { true , true , true } , false ) ]
393
+ [ InlineData ( 4 , new bool [ ] { true , false , true } , false ) ]
394
+ public void CanScale_ReturnsExpected ( int maxWorkerCount , bool [ ] isReadyArray , bool result )
395
+ {
396
+ TestEnvironment testEnvironment = new TestEnvironment ( ) ;
397
+ Mock < IFunctionInvocationDispatcherFactory > functionInvocationDispatcherFactory = new Mock < IFunctionInvocationDispatcherFactory > ( MockBehavior . Strict ) ;
398
+ Mock < IFunctionsHostingConfiguration > conf = new Mock < IFunctionsHostingConfiguration > ( ) ;
399
+ WorkerConcurrencyOptions options = new WorkerConcurrencyOptions ( ) ;
400
+ options . MaxWorkerCount = maxWorkerCount ;
401
+
402
+ WorkerConcurrencyManager concurrencyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , testEnvironment ,
403
+ Options . Create ( options ) , conf . Object , _applicationLifetime , _loggerFactory ) ;
404
+
405
+ List < IRpcWorkerChannel > workerChannels = new List < IRpcWorkerChannel > ( ) ;
406
+ foreach ( bool isReady in isReadyArray )
407
+ {
408
+ Mock < IRpcWorkerChannel > mock = new Mock < IRpcWorkerChannel > ( ) ;
409
+ mock . Setup ( x => x . IsChannelReadyForInvocations ( ) ) . Returns ( isReady ) ;
410
+ workerChannels . Add ( mock . Object ) ;
411
+ }
412
+ Assert . Equal ( concurrencyManager . CanScale ( workerChannels ) , result ) ;
413
+ }
414
+
415
+ [ Fact ]
416
+ public void OnTimer_WorksAsExpected_IfPlaceholderMode_Enabled ( )
417
+ {
418
+ TestEnvironment testEnvironment = new TestEnvironment ( ) ;
419
+ Mock < IFunctionInvocationDispatcherFactory > functionInvocationDispatcherFactory = new Mock < IFunctionInvocationDispatcherFactory > ( MockBehavior . Strict ) ;
420
+ Mock < IFunctionsHostingConfiguration > conf = new Mock < IFunctionsHostingConfiguration > ( ) ;
421
+ WorkerConcurrencyOptions options = new WorkerConcurrencyOptions ( ) ;
422
+
423
+ WorkerConcurrencyManager concurrencyManager = new WorkerConcurrencyManager ( functionInvocationDispatcherFactory . Object , testEnvironment ,
424
+ Options . Create ( options ) , conf . Object , _applicationLifetime , _loggerFactory ) ;
425
+
426
+ testEnvironment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsitePlaceholderMode , "1" ) ;
427
+ concurrencyManager . OnTimer ( null , null ) ;
428
+ Assert . Empty ( _loggerProvider . GetAllLogMessages ( ) . Where ( x => x . FormattedMessage == "Error monitoring worker concurrency" ) ) ;
429
+ }
389
430
}
390
431
}
0 commit comments