Merge branch 'release/2.2'
This commit is contained in:
commit
a677464ed0
|
|
@ -9,7 +9,16 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
public class MockSystemClock : ISystemClock
|
public class MockSystemClock : ISystemClock
|
||||||
{
|
{
|
||||||
private long _utcNowTicks = DateTimeOffset.UtcNow.Ticks;
|
private static Random _random = new Random();
|
||||||
|
|
||||||
|
private long _utcNowTicks;
|
||||||
|
|
||||||
|
public MockSystemClock()
|
||||||
|
{
|
||||||
|
// Use a random DateTimeOffset to ensure tests that incorrectly use the current DateTimeOffset fail always instead of only rarely.
|
||||||
|
// Pick a date between the min DateTimeOffset and a day before the max DateTimeOffset so there's room to advance the clock.
|
||||||
|
_utcNowTicks = NextLong(DateTimeOffset.MinValue.Ticks, DateTimeOffset.MaxValue.Ticks - TimeSpan.FromDays(1).Ticks);
|
||||||
|
}
|
||||||
|
|
||||||
public DateTimeOffset UtcNow
|
public DateTimeOffset UtcNow
|
||||||
{
|
{
|
||||||
|
|
@ -29,5 +38,10 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
public DateTimeOffset UtcNowUnsynchronized => UtcNow;
|
public DateTimeOffset UtcNowUnsynchronized => UtcNow;
|
||||||
|
|
||||||
public int UtcNowCalled { get; private set; }
|
public int UtcNowCalled { get; private set; }
|
||||||
|
|
||||||
|
private long NextLong(long minValue, long maxValue)
|
||||||
|
{
|
||||||
|
return (long)(_random.NextDouble() * (maxValue - minValue) + minValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanUpgradeRequestWithConnectionKeepAliveUpgradeHeader()
|
public async Task CanUpgradeRequestWithConnectionKeepAliveUpgradeHeader()
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
|
||||||
var dataRead = false;
|
var dataRead = false;
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
|
|
@ -154,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
await connection.ReceiveEnd(
|
await connection.ReceiveEnd(
|
||||||
"HTTP/1.1 101 Switching Protocols",
|
"HTTP/1.1 101 Switching Protocols",
|
||||||
"Connection: Upgrade",
|
"Connection: Upgrade",
|
||||||
$"Date: {testContext.DateHeaderValue}",
|
$"Date: {server.Context.DateHeaderValue}",
|
||||||
"",
|
"",
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue