@@ -557,7 +557,7 @@ public async Task TransportEndingGracefullyWaitsOnApplicationLongPolling()
557557 await task . DefaultTimeout ( ) ;
558558
559559 // We've been gone longer than the expiration time
560- connection . LastSeenTicks = Environment . TickCount64 - ( long ) disconnectTimeout . TotalMilliseconds - 1 ;
560+ connection . LastSeenTicks = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) - disconnectTimeout - TimeSpan . FromTicks ( 1 ) ;
561561
562562 // The application is still running here because the poll is only killed
563563 // by the heartbeat so we pretend to do a scan and this should force the application task to complete
@@ -1190,6 +1190,7 @@ bool ExpectedErrors(WriteContext writeContext)
11901190
11911191 using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
11921192 {
1193+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
11931194 var manager = CreateConnectionManager ( LoggerFactory ) ;
11941195 var connection = manager . CreateConnection ( ) ;
11951196 connection . TransportType = HttpTransportType . LongPolling ;
@@ -1200,16 +1201,23 @@ bool ExpectedErrors(WriteContext writeContext)
12001201 var builder = new ConnectionBuilder ( services . BuildServiceProvider ( ) ) ;
12011202 builder . UseConnectionHandler < TestConnectionHandler > ( ) ;
12021203 var app = builder . Build ( ) ;
1203- var options = new HttpConnectionDispatcherOptions ( ) ;
12041204 // First poll completes immediately
1205+ var options = new HttpConnectionDispatcherOptions ( ) ;
12051206 await dispatcher . ExecuteAsync ( context , options , app ) . DefaultTimeout ( ) ;
12061207 var sync = new SyncPoint ( ) ;
12071208 context . Response . Body = new BlockingStream ( sync ) ;
12081209 var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
12091210 await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
12101211 await sync . WaitForSyncPoint ( ) . DefaultTimeout ( ) ;
1212+
1213+ // Try cancel before cancellation should occur
1214+ connection . TryCancelSend ( initialTime + options . TransportSendTimeout ) ;
1215+ Assert . False ( connection . SendingToken . IsCancellationRequested ) ;
1216+
12111217 // Cancel write to response body
1212- connection . TryCancelSend ( long . MaxValue ) ;
1218+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1219+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1220+
12131221 sync . Continue ( ) ;
12141222 await dispatcherTask . DefaultTimeout ( ) ;
12151223 // Connection should be removed on canceled write
@@ -1223,6 +1231,7 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
12231231 {
12241232 using ( StartVerifiableLog ( ) )
12251233 {
1234+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
12261235 var manager = CreateConnectionManager ( LoggerFactory ) ;
12271236 var connection = manager . CreateConnection ( ) ;
12281237 connection . TransportType = HttpTransportType . ServerSentEvents ;
@@ -1240,8 +1249,15 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
12401249 var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
12411250 await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
12421251 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+
12431257 // Cancel write to response body
1244- connection . TryCancelSend ( long . MaxValue ) ;
1258+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1259+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1260+
12451261 sync . Continue ( ) ;
12461262 await dispatcherTask . DefaultTimeout ( ) ;
12471263 // Connection should be removed on canceled write
@@ -1260,6 +1276,7 @@ bool ExpectedErrors(WriteContext writeContext)
12601276 }
12611277 using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
12621278 {
1279+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
12631280 var manager = CreateConnectionManager ( LoggerFactory ) ;
12641281 var connection = manager . CreateConnection ( ) ;
12651282 connection . TransportType = HttpTransportType . WebSockets ;
@@ -1277,8 +1294,15 @@ bool ExpectedErrors(WriteContext writeContext)
12771294 var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
12781295 await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
12791296 await sync . WaitForSyncPoint ( ) . DefaultTimeout ( ) ;
1297+
1298+ // Try cancel before cancellation should occur
1299+ connection . TryCancelSend ( initialTime + options . TransportSendTimeout ) ;
1300+ Assert . False ( connection . SendingToken . IsCancellationRequested ) ;
1301+
12801302 // Cancel write to response body
1281- connection . TryCancelSend ( long . MaxValue ) ;
1303+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1304+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1305+
12821306 sync . Continue ( ) ;
12831307 await dispatcherTask . DefaultTimeout ( ) ;
12841308 // Connection should be removed on canceled write
0 commit comments