Skip to content

Commit 2853b45

Browse files
committed
Add RequestAbortedTokenIsUsableAfterCancellation test
1 parent 5d554ae commit 2853b45

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public Http1ConnectionTests()
5353
var connectionFeatures = new FeatureCollection();
5454
connectionFeatures.Set(Mock.Of<IConnectionLifetimeFeature>());
5555

56-
_serviceContext = new TestServiceContext();
56+
_serviceContext = new TestServiceContext()
57+
{
58+
Scheduler = PipeScheduler.Inline
59+
};
60+
5761
_timeoutControl = new Mock<ITimeoutControl>();
5862
_http1ConnectionContext = new HttpConnectionContext
5963
{
@@ -724,6 +728,27 @@ public async Task RequestAbortedTokenIsResetBeforeLastWriteWithChunkedEncoding()
724728
Assert.False(_http1Connection.RequestAborted.IsCancellationRequested);
725729
}
726730

731+
[Fact]
732+
public void RequestAbortedTokenIsUsableAfterCancellation()
733+
{
734+
var originalToken = _http1Connection.RequestAborted;
735+
var originalRegistration = originalToken.Register(() => { });
736+
737+
_http1Connection.Abort(new ConnectionAbortedException());
738+
739+
// The following line will throw an ODE because the original CTS backing the token has been diposed.
740+
// See https://github.com/aspnet/AspNetCore/pull/4447 for the history behind this test.
741+
//Assert.True(originalToken.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
742+
Assert.True(_http1Connection.RequestAborted.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
743+
744+
#if NETCOREAPP2_2
745+
Assert.Equal(originalToken, originalRegistration.Token);
746+
#elif NET461
747+
#else
748+
#error Target framework needs to be updated
749+
#endif
750+
}
751+
727752
[Fact]
728753
public async Task ExceptionDetailNotIncludedWhenLogLevelInformationNotEnabled()
729754
{

0 commit comments

Comments
 (0)