ready for final review
This commit is contained in:
parent
3e6f70d5e8
commit
5e85b3773b
|
|
@ -79,10 +79,10 @@
|
|||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.HttpOverrides" ProjectPath="$(RepoRoot)src\Middleware\HttpOverrides\src\Microsoft.AspNetCore.HttpOverrides.csproj" RefProjectPath="$(RepoRoot)src\Middleware\HttpOverrides\ref\Microsoft.AspNetCore.HttpOverrides.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.HttpsPolicy" ProjectPath="$(RepoRoot)src\Middleware\HttpsPolicy\src\Microsoft.AspNetCore.HttpsPolicy.csproj" RefProjectPath="$(RepoRoot)src\Middleware\HttpsPolicy\ref\Microsoft.AspNetCore.HttpsPolicy.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Localization.Routing" ProjectPath="$(RepoRoot)src\Middleware\Localization.Routing\src\Microsoft.AspNetCore.Localization.Routing.csproj" RefProjectPath="$(RepoRoot)src\Middleware\Localization.Routing\ref\Microsoft.AspNetCore.Localization.Routing.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.RequestThrottling" ProjectPath="$(RepoRoot)src\Middleware\RequestThrottling\src\Microsoft.AspNetCore.RequestThrottling.csproj" RefProjectPath="$(RepoRoot)src\Middleware\RequestThrottling\ref\Microsoft.AspNetCore.RequestThrottling.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Localization" ProjectPath="$(RepoRoot)src\Middleware\Localization\src\Microsoft.AspNetCore.Localization.csproj" RefProjectPath="$(RepoRoot)src\Middleware\Localization\ref\Microsoft.AspNetCore.Localization.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.MiddlewareAnalysis" ProjectPath="$(RepoRoot)src\Middleware\MiddlewareAnalysis\src\Microsoft.AspNetCore.MiddlewareAnalysis.csproj" RefProjectPath="$(RepoRoot)src\Middleware\MiddlewareAnalysis\ref\Microsoft.AspNetCore.MiddlewareAnalysis.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.NodeServices" ProjectPath="$(RepoRoot)src\Middleware\NodeServices\src\Microsoft.AspNetCore.NodeServices.csproj" RefProjectPath="$(RepoRoot)src\Middleware\NodeServices\ref\Microsoft.AspNetCore.NodeServices.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.RequestThrottling" ProjectPath="$(RepoRoot)src\Middleware\RequestThrottling\src\Microsoft.AspNetCore.RequestThrottling.csproj" RefProjectPath="$(RepoRoot)src\Middleware\RequestThrottling\ref\Microsoft.AspNetCore.RequestThrottling.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.ResponseCaching.Abstractions" ProjectPath="$(RepoRoot)src\Middleware\ResponseCaching.Abstractions\src\Microsoft.AspNetCore.ResponseCaching.Abstractions.csproj" RefProjectPath="$(RepoRoot)src\Middleware\ResponseCaching.Abstractions\ref\Microsoft.AspNetCore.ResponseCaching.Abstractions.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.ResponseCaching" ProjectPath="$(RepoRoot)src\Middleware\ResponseCaching\src\Microsoft.AspNetCore.ResponseCaching.csproj" RefProjectPath="$(RepoRoot)src\Middleware\ResponseCaching\ref\Microsoft.AspNetCore.ResponseCaching.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.ResponseCompression" ProjectPath="$(RepoRoot)src\Middleware\ResponseCompression\src\Microsoft.AspNetCore.ResponseCompression.csproj" RefProjectPath="$(RepoRoot)src\Middleware\ResponseCompression\ref\Microsoft.AspNetCore.ResponseCompression.csproj" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"solution": {
|
||||
"path": "..\\Middleware.sln",
|
||||
"projects": [
|
||||
"..\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj",
|
||||
"..\\Hosting\\Hosting\\src\\Microsoft.AspNetCore.Hosting.csproj",
|
||||
"..\\Hosting\\Server.Abstractions\\src\\Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj",
|
||||
"..\\Http\\Http.Abstractions\\src\\Microsoft.AspNetCore.Http.Abstractions.csproj",
|
||||
"..\\Http\\Http.Extensions\\src\\Microsoft.AspNetCore.Http.Extensions.csproj",
|
||||
"..\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj",
|
||||
"..\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj",
|
||||
"..\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj",
|
||||
"..\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj",
|
||||
"..\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj",
|
||||
"..\\Servers\\Kestrel\\Transport.Abstractions\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj",
|
||||
"..\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj",
|
||||
"..\\http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj",
|
||||
"..\\http\\http\\src\\Microsoft.AspNetCore.Http.csproj",
|
||||
"HttpsPolicy\\src\\Microsoft.AspNetCore.HttpsPolicy.csproj",
|
||||
"RequestThrottling\\sample\\RequestThrottlingSample.csproj",
|
||||
"RequestThrottling\\src\\Microsoft.AspNetCore.RequestThrottling.csproj",
|
||||
"RequestThrottling\\test\\Microsoft.AspNetCore.RequestThrottling.Tests.csproj"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ using Microsoft.Extensions.Hosting;
|
|||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace RequestThrottlingSample
|
||||
{
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
|
|
@ -26,9 +26,7 @@ namespace RequestThrottlingSample
|
|||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
Console.WriteLine("HEWWWO?");
|
||||
await context.Response.WriteAsync("Hello world!");
|
||||
Console.WriteLine("GOODBWWYWE!");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,6 @@ using Microsoft.AspNetCore.Testing;
|
|||
|
||||
namespace Microsoft.AspNetCore.RequestThrottling.Tests
|
||||
{
|
||||
public static class TaskExtensions
|
||||
{
|
||||
public static Task OrTimeout(this Task task, int seconds = 30)
|
||||
{
|
||||
return task.TimeoutAfter(TimeSpan.FromSeconds(seconds));
|
||||
}
|
||||
}
|
||||
public class SemaphoreWrapperTests
|
||||
{
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
// 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.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
|
||||
namespace System.Threading.Tasks
|
||||
{
|
||||
#if TESTUTILS
|
||||
public
|
||||
#else
|
||||
internal
|
||||
#endif
|
||||
static class TaskExtensions
|
||||
{
|
||||
private const int DefaultTimeout = 30 * 1000;
|
||||
|
||||
public static Task OrTimeout(this Task task, int milliseconds = DefaultTimeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
|
||||
{
|
||||
return OrTimeout(task, new TimeSpan(0, 0, 0, 0, milliseconds), memberName, filePath, lineNumber);
|
||||
}
|
||||
|
||||
public static Task OrTimeout(this Task task, TimeSpan timeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
|
||||
{
|
||||
return task.TimeoutAfter(timeout, filePath, lineNumber ?? 0);
|
||||
}
|
||||
|
||||
public static Task<T> OrTimeout<T>(this ValueTask<T> task, int milliseconds = DefaultTimeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null) =>
|
||||
OrTimeout(task, new TimeSpan(0, 0, 0, 0, milliseconds), memberName, filePath, lineNumber);
|
||||
|
||||
public static Task<T> OrTimeout<T>(this ValueTask<T> task, TimeSpan timeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null) =>
|
||||
task.AsTask().OrTimeout(timeout, memberName, filePath, lineNumber);
|
||||
|
||||
public static Task<T> OrTimeout<T>(this Task<T> task, int milliseconds = DefaultTimeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
|
||||
{
|
||||
return OrTimeout(task, new TimeSpan(0, 0, 0, 0, milliseconds), memberName, filePath, lineNumber);
|
||||
}
|
||||
|
||||
public static Task<T> OrTimeout<T>(this Task<T> task, TimeSpan timeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
|
||||
{
|
||||
return task.TimeoutAfter(timeout, filePath, lineNumber ?? 0);
|
||||
}
|
||||
|
||||
public static async Task OrThrowIfOtherFails(this Task task, Task otherTask)
|
||||
{
|
||||
var completed = await Task.WhenAny(task, otherTask);
|
||||
if (completed == otherTask && otherTask.IsFaulted)
|
||||
{
|
||||
// Manifest the exception
|
||||
otherTask.GetAwaiter().GetResult();
|
||||
throw new Exception("Unreachable code");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Await the task we were asked to await. Either it's finished, or the otherTask finished successfully, and it's not our job to check that
|
||||
await task;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T> OrThrowIfOtherFails<T>(this Task<T> task, Task otherTask)
|
||||
{
|
||||
await OrThrowIfOtherFails((Task)task, otherTask);
|
||||
|
||||
// If we get here, 'task' is finished and succeeded.
|
||||
return task.GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue