@@ -552,7 +552,7 @@ public async Task TransportEndingGracefullyWaitsOnApplicationLongPolling()
552552 await task . DefaultTimeout ( ) ;
553553
554554 // We've been gone longer than the expiration time
555- connection . LastSeenTicks = Environment . TickCount64 - ( long ) disconnectTimeout . TotalMilliseconds - 1 ;
555+ connection . LastSeenTicks = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) - disconnectTimeout - TimeSpan . FromTicks ( 1 ) ;
556556
557557 // The application is still running here because the poll is only killed
558558 // by the heartbeat so we pretend to do a scan and this should force the application task to complete
@@ -1145,6 +1145,7 @@ bool ExpectedErrors(WriteContext writeContext)
11451145
11461146 using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
11471147 {
1148+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
11481149 var manager = CreateConnectionManager ( LoggerFactory ) ;
11491150 var connection = manager . CreateConnection ( ) ;
11501151 connection . TransportType = HttpTransportType . LongPolling ;
@@ -1163,8 +1164,15 @@ bool ExpectedErrors(WriteContext writeContext)
11631164 var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
11641165 await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
11651166 await sync . WaitForSyncPoint ( ) . DefaultTimeout ( ) ;
1167+
1168+ // Try cancel before cancellation should occur
1169+ connection . TryCancelSend ( initialTime + options . TransportSendTimeout ) ;
1170+ Assert . False ( connection . SendingToken . IsCancellationRequested ) ;
1171+
11661172 // Cancel write to response body
1167- connection . TryCancelSend ( long . MaxValue ) ;
1173+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1174+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1175+
11681176 sync . Continue ( ) ;
11691177 await dispatcherTask . DefaultTimeout ( ) ;
11701178 // Connection should be removed on canceled write
@@ -1178,6 +1186,7 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
11781186 {
11791187 using ( StartVerifiableLog ( ) )
11801188 {
1189+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
11811190 var manager = CreateConnectionManager ( LoggerFactory ) ;
11821191 var connection = manager . CreateConnection ( ) ;
11831192 connection . TransportType = HttpTransportType . ServerSentEvents ;
@@ -1195,8 +1204,15 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
11951204 var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
11961205 await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
11971206 await sync . WaitForSyncPoint ( ) . DefaultTimeout ( ) ;
1207+
1208+ // Try cancel before cancellation should occur
1209+ connection . TryCancelSend ( initialTime + options . TransportSendTimeout ) ;
1210+ Assert . False ( connection . SendingToken . IsCancellationRequested ) ;
1211+
11981212 // Cancel write to response body
1199- connection . TryCancelSend ( long . MaxValue ) ;
1213+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1214+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1215+
12001216 sync . Continue ( ) ;
12011217 await dispatcherTask . DefaultTimeout ( ) ;
12021218 // Connection should be removed on canceled write
@@ -1215,6 +1231,7 @@ bool ExpectedErrors(WriteContext writeContext)
12151231 }
12161232 using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
12171233 {
1234+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
12181235 var manager = CreateConnectionManager ( LoggerFactory ) ;
12191236 var connection = manager . CreateConnection ( ) ;
12201237 connection . TransportType = HttpTransportType . WebSockets ;
@@ -1232,8 +1249,15 @@ bool ExpectedErrors(WriteContext writeContext)
12321249 var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
12331250 await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
12341251 await sync . WaitForSyncPoint ( ) . DefaultTimeout ( ) ;
1252+
1253+ // Try cancel before cancellation should occur
1254+ connection . TryCancelSend ( initialTime + options . TransportSendTimeout ) ;
1255+ Assert . False ( connection . SendingToken . IsCancellationRequested ) ;
1256+
12351257 // Cancel write to response body
1236- connection . TryCancelSend ( long . MaxValue ) ;
1258+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1259+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1260+
12371261 sync . Continue ( ) ;
12381262 await dispatcherTask . DefaultTimeout ( ) ;
12391263 // Connection should be removed on canceled write
0 commit comments