12
12
using Microsoft . AspNetCore . Http . Features ;
13
13
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http3 ;
14
14
using Microsoft . AspNetCore . Testing ;
15
+ using Microsoft . Extensions . Logging ;
15
16
using Microsoft . Net . Http . Headers ;
16
17
using Xunit ;
17
18
using Http3SettingType = Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http3 . Http3SettingType ;
@@ -90,6 +91,8 @@ public async Task GOAWAY_GracefulServerShutdown_SendsGoAway(int connectionReques
90
91
await request . SendHeadersAsync ( Headers ) ;
91
92
await request . EndStreamAsync ( ) ;
92
93
await request . ExpectReceiveEndOfStream ( ) ;
94
+
95
+ await request . OnStreamCompletedTask . DefaultTimeout ( ) ;
93
96
}
94
97
95
98
// Trigger server shutdown.
@@ -272,16 +275,16 @@ public async Task StreamPool_MultipleStreamsInSequence_PooledStreamReused()
272
275
273
276
await Http3Api . InitializeConnectionAsync ( _echoApplication ) ;
274
277
275
- var streamContext1 = await MakeRequestAsync ( 0 , headers ) ;
276
- var streamContext2 = await MakeRequestAsync ( 1 , headers ) ;
278
+ var streamContext1 = await MakeRequestAsync ( 0 , headers , sendData : true , waitForServerDispose : true ) ;
279
+ var streamContext2 = await MakeRequestAsync ( 1 , headers , sendData : true , waitForServerDispose : true ) ;
277
280
278
281
Assert . Same ( streamContext1 , streamContext2 ) ;
279
282
}
280
283
281
284
[ Theory ]
282
285
[ InlineData ( 10 ) ]
283
286
[ InlineData ( 100 ) ]
284
- [ InlineData ( 1000 ) ]
287
+ [ InlineData ( 500 ) ]
285
288
[ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/34685" ) ]
286
289
public async Task StreamPool_VariableMultipleStreamsInSequence_PooledStreamReused ( int count )
287
290
{
@@ -299,40 +302,82 @@ public async Task StreamPool_VariableMultipleStreamsInSequence_PooledStreamReuse
299
302
ConnectionContext last = null ;
300
303
for ( var i = 0 ; i < count ; i ++ )
301
304
{
302
- var streamContext = await MakeRequestAsync ( i , headers ) ;
305
+ Logger . LogInformation ( $ "Iteration { i } ") ;
306
+
307
+ var streamContext = await MakeRequestAsync ( i , headers , sendData : true , waitForServerDispose : true ) ;
303
308
304
309
first ??= streamContext ;
305
310
last = streamContext ;
311
+
312
+ Assert . Same ( first , last ) ;
306
313
}
314
+ }
315
+
316
+ [ Theory ]
317
+ [ InlineData ( 10 , false ) ]
318
+ [ InlineData ( 10 , true ) ]
319
+ [ InlineData ( 100 , false ) ]
320
+ [ InlineData ( 100 , true ) ]
321
+ [ InlineData ( 500 , false ) ]
322
+ [ InlineData ( 500 , true ) ]
323
+ [ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/34685" ) ]
324
+ public async Task VariableMultipleStreamsInSequence_Success ( int count , bool sendData )
325
+ {
326
+ var headers = new [ ]
327
+ {
328
+ new KeyValuePair < string , string > ( HeaderNames . Method , "Custom" ) ,
329
+ new KeyValuePair < string , string > ( HeaderNames . Path , "/" ) ,
330
+ new KeyValuePair < string , string > ( HeaderNames . Scheme , "http" ) ,
331
+ new KeyValuePair < string , string > ( HeaderNames . Authority , "localhost:80" ) ,
332
+ } ;
333
+
334
+ var requestDelegate = sendData ? _echoApplication : _noopApplication ;
307
335
308
- Assert . Same ( first , last ) ;
336
+ await Http3Api . InitializeConnectionAsync ( requestDelegate ) ;
337
+
338
+ for ( var i = 0 ; i < count ; i ++ )
339
+ {
340
+ Logger . LogInformation ( $ "Iteration { i } ") ;
341
+
342
+ await MakeRequestAsync ( i , headers , sendData , waitForServerDispose : false ) ;
343
+ }
309
344
}
310
345
311
- private async Task < ConnectionContext > MakeRequestAsync ( int index , KeyValuePair < string , string > [ ] headers )
346
+ private async Task < ConnectionContext > MakeRequestAsync ( int index , KeyValuePair < string , string > [ ] headers , bool sendData , bool waitForServerDispose )
312
347
{
313
348
var requestStream = await Http3Api . CreateRequestStream ( ) ;
314
349
var streamContext = requestStream . StreamContext ;
315
350
316
- await requestStream . SendHeadersAsync ( headers ) ;
351
+ await requestStream . SendHeadersAsync ( headers , endStream : ! sendData ) ;
317
352
318
- await requestStream . SendDataAsync ( Encoding . ASCII . GetBytes ( $ "Hello world { index } ") ) ;
353
+ if ( sendData )
354
+ {
355
+ await requestStream . SendDataAsync ( Encoding . ASCII . GetBytes ( $ "Hello world { index } ") ) ;
356
+ }
319
357
320
358
await requestStream . ExpectHeadersAsync ( ) ;
321
- var responseData = await requestStream . ExpectDataAsync ( ) ;
322
- Assert . Equal ( $ "Hello world { index } ", Encoding . ASCII . GetString ( responseData . ToArray ( ) ) ) ;
323
359
324
- Assert . False ( requestStream . Disposed , "Request is in progress and shouldn't be disposed." ) ;
360
+ if ( sendData )
361
+ {
362
+ var responseData = await requestStream . ExpectDataAsync ( ) ;
363
+ Assert . Equal ( $ "Hello world { index } ", Encoding . ASCII . GetString ( responseData . ToArray ( ) ) ) ;
364
+
365
+ Assert . False ( requestStream . Disposed , "Request is in progress and shouldn't be disposed." ) ;
325
366
326
- await requestStream . SendDataAsync ( Encoding . ASCII . GetBytes ( $ "End { index } ") , endStream : true ) ;
327
- responseData = await requestStream . ExpectDataAsync ( ) ;
328
- Assert . Equal ( $ "End { index } ", Encoding . ASCII . GetString ( responseData . ToArray ( ) ) ) ;
367
+ await requestStream . SendDataAsync ( Encoding . ASCII . GetBytes ( $ "End { index } ") , endStream : true ) ;
368
+ responseData = await requestStream . ExpectDataAsync ( ) ;
369
+ Assert . Equal ( $ "End { index } ", Encoding . ASCII . GetString ( responseData . ToArray ( ) ) ) ;
370
+ }
329
371
330
372
await requestStream . ExpectReceiveEndOfStream ( ) ;
331
373
332
- await requestStream . OnStreamCompletedTask . DefaultTimeout ( ) ;
374
+ if ( waitForServerDispose )
375
+ {
376
+ await requestStream . OnDisposedTask . DefaultTimeout ( ) ;
377
+ Assert . True ( requestStream . Disposed , "Request is complete and should be disposed." ) ;
333
378
334
- await requestStream . OnDisposedTask . DefaultTimeout ( ) ;
335
- Assert . True ( requestStream . Disposed , "Request is complete and should be disposed." ) ;
379
+ Logger . LogInformation ( $ "Received notification that stream { index } disposed." ) ;
380
+ }
336
381
337
382
return streamContext ;
338
383
}
0 commit comments