@@ -552,7 +552,7 @@ public async Task TransportEndingGracefullyWaitsOnApplicationLongPolling()
552
552
await task . DefaultTimeout ( ) ;
553
553
554
554
// 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 ) ;
556
556
557
557
// The application is still running here because the poll is only killed
558
558
// 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)
1145
1145
1146
1146
using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
1147
1147
{
1148
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1148
1149
var manager = CreateConnectionManager ( LoggerFactory ) ;
1149
1150
var connection = manager . CreateConnection ( ) ;
1150
1151
connection . TransportType = HttpTransportType . LongPolling ;
@@ -1163,8 +1164,15 @@ bool ExpectedErrors(WriteContext writeContext)
1163
1164
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1164
1165
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1165
1166
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
+
1166
1172
// 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
+
1168
1176
sync . Continue ( ) ;
1169
1177
await dispatcherTask . DefaultTimeout ( ) ;
1170
1178
// Connection should be removed on canceled write
@@ -1178,6 +1186,7 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
1178
1186
{
1179
1187
using ( StartVerifiableLog ( ) )
1180
1188
{
1189
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1181
1190
var manager = CreateConnectionManager ( LoggerFactory ) ;
1182
1191
var connection = manager . CreateConnection ( ) ;
1183
1192
connection . TransportType = HttpTransportType . ServerSentEvents ;
@@ -1195,8 +1204,15 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
1195
1204
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1196
1205
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1197
1206
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
+
1198
1212
// 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
+
1200
1216
sync . Continue ( ) ;
1201
1217
await dispatcherTask . DefaultTimeout ( ) ;
1202
1218
// Connection should be removed on canceled write
@@ -1215,6 +1231,7 @@ bool ExpectedErrors(WriteContext writeContext)
1215
1231
}
1216
1232
using ( StartVerifiableLog ( expectedErrorsFilter : ExpectedErrors ) )
1217
1233
{
1234
+ var initialTime = TimeSpan . FromMilliseconds ( Environment . TickCount64 ) ;
1218
1235
var manager = CreateConnectionManager ( LoggerFactory ) ;
1219
1236
var connection = manager . CreateConnection ( ) ;
1220
1237
connection . TransportType = HttpTransportType . WebSockets ;
@@ -1232,8 +1249,15 @@ bool ExpectedErrors(WriteContext writeContext)
1232
1249
var dispatcherTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1233
1250
await connection . Transport . Output . WriteAsync ( new byte [ ] { 1 } ) . DefaultTimeout ( ) ;
1234
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
+
1235
1257
// 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
+
1237
1261
sync . Continue ( ) ;
1238
1262
await dispatcherTask . DefaultTimeout ( ) ;
1239
1263
// Connection should be removed on canceled write
0 commit comments