Add functional style request aborted test (#1406)
This commit is contained in:
parent
608889b110
commit
4e57b0e1f1
|
|
@ -43,5 +43,23 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
var responseText = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal("Hello World", responseText);
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
public async Task RequestAbortedTokenFires()
|
||||
{
|
||||
using (var connection = _fixture.CreateTestConnection())
|
||||
{
|
||||
await connection.Send(
|
||||
"GET /WaitForAbort HTTP/1.1",
|
||||
"Host: localhost",
|
||||
"Connection: close",
|
||||
"",
|
||||
"");
|
||||
|
||||
await _fixture.Client.RetryRequestAsync("/WaitingRequestCount", async message => await message.Content.ReadAsStringAsync() == "1");
|
||||
}
|
||||
|
||||
await _fixture.Client.RetryRequestAsync("/WaitingRequestCount", async message => await message.Content.ReadAsStringAsync() == "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
|
@ -49,5 +50,26 @@ namespace TestSite
|
|||
var clientCert = context.Connection.ClientCertificate;
|
||||
await context.Response.WriteAsync(clientCert != null ? $"Enabled;{clientCert.GetCertHashString()}" : "Disabled");
|
||||
}
|
||||
|
||||
private static int _waitingRequestCount;
|
||||
|
||||
public Task WaitForAbort(HttpContext context)
|
||||
{
|
||||
Interlocked.Increment(ref _waitingRequestCount);
|
||||
try
|
||||
{
|
||||
context.RequestAborted.WaitHandle.WaitOne();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Interlocked.Decrement(ref _waitingRequestCount);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task WaitingRequestCount(HttpContext context)
|
||||
{
|
||||
await context.Response.WriteAsync(_waitingRequestCount.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue