|
3 | 3 |
|
4 | 4 | using System; |
5 | 5 | using System.Collections.Generic; |
| 6 | +using System.Diagnostics; |
6 | 7 | using System.Linq; |
7 | 8 | using System.Threading; |
8 | 9 | using System.Threading.Tasks; |
| 10 | +using Microsoft.Azure.WebJobs.Host.Scale; |
9 | 11 | using Microsoft.Azure.WebJobs.Script.Config; |
10 | 12 | using Microsoft.Azure.WebJobs.Script.Workers; |
11 | 13 | using Microsoft.Azure.WebJobs.Script.Workers.Rpc; |
@@ -354,12 +356,35 @@ public async Task ActivateWorkerConcurency_FunctionsHostingConfiguration_WorkAsE |
354 | 356 | conf.Setup(x => x.FunctionsWorkerDynamicConcurrencyEnabled).Returns(true); |
355 | 357 | WorkerConcurrencyOptions options = new WorkerConcurrencyOptions(); |
356 | 358 |
|
357 | | - WorkerConcurrencyManager concurrancyManager = new WorkerConcurrencyManager(functionInvocationDispatcherFactory.Object, testEnvironment, Options.Create(options), conf.Object, _applicationLifetime, _loggerFactory); |
| 359 | + WorkerConcurrencyManager concurrancyManager = new WorkerConcurrencyManager(functionInvocationDispatcherFactory.Object, testEnvironment, Options.Create(options), conf.Object, |
| 360 | + _applicationLifetime, _loggerFactory); |
358 | 361 | concurrancyManager.ActivationTimerInterval = TimeSpan.FromMilliseconds(100); |
359 | 362 | await concurrancyManager.StartAsync(CancellationToken.None); |
360 | 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); |
361 | 364 | conf.Setup(x => x.FunctionsWorkerDynamicConcurrencyEnabled).Returns(false); |
362 | 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); |
363 | 366 | } |
| 367 | + |
| 368 | + [Theory] |
| 369 | + [InlineData(100, 20, new long[] { 20, 20 }, true)] |
| 370 | + [InlineData(100, 20, new long[] { 20, 10, 10 }, true)] |
| 371 | + [InlineData(100, 21, new long[] { 20, 10, 10 }, false)] |
| 372 | + public void IsEnoughMemory_WorkAsExpected(long availableMemory, long hostProcessSize, IEnumerable<long> languageWorkerSizes, bool result) |
| 373 | + { |
| 374 | + TestEnvironment testEnvironment = new TestEnvironment(); |
| 375 | + Mock<IFunctionInvocationDispatcher> functionInvocationDispatcher = new Mock<IFunctionInvocationDispatcher>(MockBehavior.Strict); |
| 376 | + Mock<IFunctionInvocationDispatcherFactory> functionInvocationDispatcherFactory = new Mock<IFunctionInvocationDispatcherFactory>(MockBehavior.Strict); |
| 377 | + Mock<IFunctionsHostingConfiguration> conf = new Mock<IFunctionsHostingConfiguration>(); |
| 378 | + WorkerConcurrencyOptions options = new WorkerConcurrencyOptions(); |
| 379 | + |
| 380 | + WorkerConcurrencyManager concurrancyManager = new WorkerConcurrencyManager(functionInvocationDispatcherFactory.Object, testEnvironment, |
| 381 | + Options.Create(options), conf.Object, _applicationLifetime, _loggerFactory); |
| 382 | + |
| 383 | + Assert.True(concurrancyManager.IsEnoughMemoryToScale(hostProcessSize, languageWorkerSizes, availableMemory) == result); |
| 384 | + if (!result) |
| 385 | + { |
| 386 | + Assert.Contains(_loggerProvider.GetAllLogMessages().Select(x => x.FormattedMessage), x => x.StartsWith("Starting new language worker canceled:")); |
| 387 | + } |
| 388 | + } |
364 | 389 | } |
365 | 390 | } |
0 commit comments