|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT License. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System.Threading.Tasks.Dataflow; |
| 5 | +using Microsoft.Azure.WebJobs.Extensions.Http; |
| 6 | +using Microsoft.Azure.WebJobs.Script.WebHost.Configuration; |
| 7 | +using Moq; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Microsoft.Azure.WebJobs.Script.Tests.Configuration |
| 11 | +{ |
| 12 | + public class HttpOptionsSetupTests |
| 13 | + { |
| 14 | + [Fact] |
| 15 | + public void Configure_Dynamic_AppService_Defaults() |
| 16 | + { |
| 17 | + var mockEnvironment = new Mock<IEnvironment>(MockBehavior.Strict); |
| 18 | + mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteInstanceId)).Returns("1234"); |
| 19 | + mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteSku)).Returns(ScriptConstants.DynamicSku); |
| 20 | + |
| 21 | + var setup = new HttpOptionsSetup(mockEnvironment.Object); |
| 22 | + var options = new HttpOptions(); |
| 23 | + setup.Configure(options); |
| 24 | + |
| 25 | + Assert.True(options.DynamicThrottlesEnabled); |
| 26 | + Assert.Equal(HttpOptionsSetup.DefaultMaxConcurrentRequests, options.MaxConcurrentRequests); |
| 27 | + Assert.Equal(HttpOptionsSetup.DefaultMaxOutstandingRequests, options.MaxOutstandingRequests); |
| 28 | + } |
| 29 | + |
| 30 | + [Fact] |
| 31 | + public void Configure_Dynamic_NonAppService_Defaults() |
| 32 | + { |
| 33 | + var mockEnvironment = new Mock<IEnvironment>(MockBehavior.Strict); |
| 34 | + mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteInstanceId)).Returns((string)null); |
| 35 | + mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteSku)).Returns(ScriptConstants.DynamicSku); |
| 36 | + |
| 37 | + var setup = new HttpOptionsSetup(mockEnvironment.Object); |
| 38 | + var options = new HttpOptions(); |
| 39 | + setup.Configure(options); |
| 40 | + |
| 41 | + Assert.False(options.DynamicThrottlesEnabled); |
| 42 | + Assert.Equal(HttpOptionsSetup.DefaultMaxConcurrentRequests, options.MaxConcurrentRequests); |
| 43 | + Assert.Equal(HttpOptionsSetup.DefaultMaxOutstandingRequests, options.MaxOutstandingRequests); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void Configure_Dedicated_DoesNotDefault() |
| 48 | + { |
| 49 | + var mockEnvironment = new Mock<IEnvironment>(MockBehavior.Strict); |
| 50 | + mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteInstanceId)).Returns("1234"); |
| 51 | + mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteSku)).Returns("Dedicated"); |
| 52 | + |
| 53 | + var setup = new HttpOptionsSetup(mockEnvironment.Object); |
| 54 | + var options = new HttpOptions(); |
| 55 | + setup.Configure(options); |
| 56 | + |
| 57 | + Assert.False(options.DynamicThrottlesEnabled); |
| 58 | + Assert.Equal(DataflowBlockOptions.Unbounded, options.MaxConcurrentRequests); |
| 59 | + Assert.Equal(DataflowBlockOptions.Unbounded, options.MaxOutstandingRequests); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments