@@ -555,7 +555,7 @@ public async Task TransportEndingGracefullyWaitsOnApplicationLongPolling()
555
555
await task . DefaultTimeout ( ) ;
556
556
557
557
// We've been gone longer than the expiration time
558
- connection . LastSeenTicks = Environment . TickCount64 - ( long ) disconnectTimeout . TotalMilliseconds - 1 ;
558
+ connection . LastSeenTicks = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) - disconnectTimeout - TimeSpan . FromTicks ( 1 ) ;
559
559
560
560
// The application is still running here because the poll is only killed
561
561
// by the heartbeat so we pretend to do a scan and this should force the application task to complete
@@ -1277,6 +1277,7 @@ bool ExpectedErrors(WriteContext writeContext)
1277
1277
1278
1278
using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
1279
1279
{
1280
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1280
1281
var manager = CreateConnectionManager ( LoggerFactory ) ;
1281
1282
var connection = manager . CreateConnection ( ) ;
1282
1283
connection . TransportType = HttpTransportType . LongPolling ;
@@ -1287,16 +1288,23 @@ bool ExpectedErrors(WriteContext writeContext)
1287
1288
var builder = new ConnectionBuilder ( services . BuildServiceProvider ( ) ) ;
1288
1289
builder . UseConnectionHandler < TestConnectionHandler > ( ) ;
1289
1290
var app = builder . Build ( ) ;
1290
- var options = new HttpConnectionDispatcherOptions ( ) ;
1291
1291
// First poll completes immediately
1292
+ var options = new HttpConnectionDispatcherOptions ( ) ;
1292
1293
await dispatcher . ExecuteAsync ( context , options , app ) . DefaultTimeout ( ) ;
1293
1294
var sync = new SyncPoint ( ) ;
1294
1295
context . Response . Body = new BlockingStream ( sync ) ;
1295
1296
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1296
1297
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1297
1298
await sync . WaitForSyncPoint ( ) . DefaultTimeout ( ) ;
1299
+
1300
+ // Try cancel before cancellation should occur
1301
+ connection . TryCancelSend ( initialTime + options . TransportSendTimeout ) ;
1302
+ Assert . False ( connection . SendingToken . IsCancellationRequested ) ;
1303
+
1298
1304
// Cancel write to response body
1299
- connection . TryCancelSend ( long . MaxValue ) ;
1305
+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1306
+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1307
+
1300
1308
sync . Continue ( ) ;
1301
1309
await dispatcherTask . DefaultTimeout ( ) ;
1302
1310
// Connection should be removed on canceled write
@@ -1310,6 +1318,7 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
1310
1318
{
1311
1319
using ( StartVerifiableLog ( ) )
1312
1320
{
1321
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1313
1322
var manager = CreateConnectionManager ( LoggerFactory ) ;
1314
1323
var connection = manager . CreateConnection ( ) ;
1315
1324
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
@@ -1326,8 +1335,15 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
1326
1335
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1327
1336
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1328
1337
await sync . WaitForSyncPoint ( ) . DefaultTimeout ( ) ;
1338
+
1339
+ // Try cancel before cancellation should occur
1340
+ connection . TryCancelSend ( initialTime + options . TransportSendTimeout ) ;
1341
+ Assert . False ( connection . SendingToken . IsCancellationRequested ) ;
1342
+
1329
1343
// Cancel write to response body
1330
- connection . TryCancelSend ( long . MaxValue ) ;
1344
+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1345
+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1346
+
1331
1347
sync . Continue ( ) ;
1332
1348
await dispatcherTask . DefaultTimeout ( ) ;
1333
1349
// Connection should be removed on canceled write
@@ -1346,6 +1362,7 @@ bool ExpectedErrors(WriteContext writeContext)
1346
1362
}
1347
1363
using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
1348
1364
{
1365
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1349
1366
var manager = CreateConnectionManager ( LoggerFactory ) ;
1350
1367
var connection = manager . CreateConnection ( ) ;
1351
1368
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
@@ -1362,8 +1379,15 @@ bool ExpectedErrors(WriteContext writeContext)
1362
1379
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1363
1380
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1364
1381
await sync . WaitForSyncPoint ( ) . DefaultTimeout ( ) ;
1382
+
1383
+ // Try cancel before cancellation should occur
1384
+ connection . TryCancelSend ( initialTime + options . TransportSendTimeout ) ;
1385
+ Assert . False ( connection . SendingToken . IsCancellationRequested ) ;
1386
+
1365
1387
// Cancel write to response body
1366
- connection . TryCancelSend ( long . MaxValue ) ;
1388
+ connection . TryCancelSend ( TimeSpan . FromMilliseconds ( Environment . TickCount64 ) + options . TransportSendTimeout + TimeSpan . FromTicks ( 1 ) ) ;
1389
+ Assert . True ( connection . SendingToken . IsCancellationRequested ) ;
1390
+
1367
1391
sync . Continue ( ) ;
1368
1392
await dispatcherTask . DefaultTimeout ( ) ;
1369
1393
// Connection should be removed on canceled write
0 commit comments