@@ -557,7 +557,7 @@ public async Task TransportEndingGracefullyWaitsOnApplicationLongPolling()
557
557
await task . DefaultTimeout ( ) ;
558
558
559
559
// 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 ) ;
561
561
562
562
// The application is still running here because the poll is only killed
563
563
// 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)
1190
1190
1191
1191
using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
1192
1192
{
1193
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1193
1194
var manager = CreateConnectionManager ( LoggerFactory ) ;
1194
1195
var connection = manager . CreateConnection ( ) ;
1195
1196
connection . TransportType = HttpTransportType . LongPolling ;
@@ -1200,16 +1201,23 @@ bool ExpectedErrors(WriteContext writeContext)
1200
1201
var builder = new ConnectionBuilder ( services . BuildServiceProvider ( ) ) ;
1201
1202
builder . UseConnectionHandler < TestConnectionHandler > ( ) ;
1202
1203
var app = builder . Build ( ) ;
1203
- var options = new HttpConnectionDispatcherOptions ( ) ;
1204
1204
// First poll completes immediately
1205
+ var options = new HttpConnectionDispatcherOptions ( ) ;
1205
1206
await dispatcher . ExecuteAsync ( context , options , app ) . DefaultTimeout ( ) ;
1206
1207
var sync = new SyncPoint ( ) ;
1207
1208
context . Response . Body = new BlockingStream ( sync ) ;
1208
1209
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1209
1210
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1210
1211
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
+
1211
1217
// 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
+
1213
1221
sync . Continue ( ) ;
1214
1222
await dispatcherTask . DefaultTimeout ( ) ;
1215
1223
// Connection should be removed on canceled write
@@ -1223,6 +1231,7 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
1223
1231
{
1224
1232
using ( StartVerifiableLog ( ) )
1225
1233
{
1234
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1226
1235
var manager = CreateConnectionManager ( LoggerFactory ) ;
1227
1236
var connection = manager . CreateConnection ( ) ;
1228
1237
connection . TransportType = HttpTransportType . ServerSentEvents ;
@@ -1240,8 +1249,15 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
1240
1249
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1241
1250
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1242
1251
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
+
1243
1257
// 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
+
1245
1261
sync . Continue ( ) ;
1246
1262
await dispatcherTask . DefaultTimeout ( ) ;
1247
1263
// Connection should be removed on canceled write
@@ -1260,6 +1276,7 @@ bool ExpectedErrors(WriteContext writeContext)
1260
1276
}
1261
1277
using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
1262
1278
{
1279
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1263
1280
var manager = CreateConnectionManager ( LoggerFactory ) ;
1264
1281
var connection = manager . CreateConnection ( ) ;
1265
1282
connection . TransportType = HttpTransportType . WebSockets ;
@@ -1277,8 +1294,15 @@ bool ExpectedErrors(WriteContext writeContext)
1277
1294
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1278
1295
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1279
1296
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
+
1280
1302
// 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
+
1282
1306
sync . Continue ( ) ;
1283
1307
await dispatcherTask . DefaultTimeout ( ) ;
1284
1308
// Connection should be removed on canceled write
0 commit comments