This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'khellang/configurable-thread-count' into dev
- Loading branch information
Showing
3 changed files
with
154 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.AspNet.Server.Kestrel; | ||
using Microsoft.Extensions.Configuration; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNet.Server.KestrelTests | ||
{ | ||
public class KestrelServerInformationTests | ||
{ | ||
[Fact] | ||
public void SetThreadCountUsingConfiguration() | ||
{ | ||
const int expected = 42; | ||
|
||
var values = new Dictionary<string, string> | ||
{ | ||
{ "kestrel.threadCount", expected.ToString() } | ||
}; | ||
|
||
var configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(values) | ||
.Build(); | ||
|
||
var information = new KestrelServerInformation(configuration); | ||
|
||
Assert.Equal(expected, information.ThreadCount); | ||
} | ||
|
||
[Fact] | ||
public void SetThreadCountUsingProcessorCount() | ||
{ | ||
// Ideally we'd mock Environment.ProcessorCount to test edge cases. | ||
var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16); | ||
|
||
var configuration = new ConfigurationBuilder().Build(); | ||
|
||
var information = new KestrelServerInformation(configuration); | ||
|
||
Assert.Equal(expected, information.ThreadCount); | ||
} | ||
|
||
[Fact] | ||
public void SetAddressesUsingConfiguration() | ||
{ | ||
var expected = new List<string> { "http://localhost:1337", "https://localhost:42" }; | ||
|
||
var values = new Dictionary<string, string> | ||
{ | ||
{ "server.urls", string.Join(";", expected) } | ||
}; | ||
|
||
var configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(values) | ||
.Build(); | ||
|
||
var information = new KestrelServerInformation(configuration); | ||
|
||
Assert.Equal(expected, information.Addresses); | ||
} | ||
|
||
[Fact] | ||
public void SetNoDelayUsingConfiguration() | ||
{ | ||
var values = new Dictionary<string, string> | ||
{ | ||
{ "kestrel.noDelay", "false" } | ||
}; | ||
|
||
var configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(values) | ||
.Build(); | ||
|
||
var information = new KestrelServerInformation(configuration); | ||
|
||
Assert.False(information.NoDelay); | ||
} | ||
|
||
private static int Clamp(int value, int min, int max) | ||
{ | ||
return value < min ? min : value > max ? max : value; | ||
} | ||
} | ||
} |