3
3
4
4
using System . Buffers ;
5
5
using System . Collections ;
6
+ using System . IO . Pipelines ;
6
7
using System . Text ;
7
8
using Microsoft . AspNetCore . Connections ;
8
9
using Microsoft . AspNetCore . Http ;
@@ -146,21 +147,6 @@ public void ResetResetsScheme()
146
147
Assert . Equal ( "http" , ( ( IFeatureCollection ) _http1Connection ) . Get < IHttpRequestFeature > ( ) . Scheme ) ;
147
148
}
148
149
149
- [ Fact ]
150
- public void ResetResetsTraceIdentifier ( )
151
- {
152
- _http1Connection . TraceIdentifier = "xyz" ;
153
-
154
- _http1Connection . Reset ( ) ;
155
-
156
- var nextId = ( ( IFeatureCollection ) _http1Connection ) . Get < IHttpRequestIdentifierFeature > ( ) . TraceIdentifier ;
157
- Assert . NotEqual ( "xyz" , nextId ) ;
158
-
159
- _http1Connection . Reset ( ) ;
160
- var secondId = ( ( IFeatureCollection ) _http1Connection ) . Get < IHttpRequestIdentifierFeature > ( ) . TraceIdentifier ;
161
- Assert . NotEqual ( nextId , secondId ) ;
162
- }
163
-
164
150
[ Fact ]
165
151
public void ResetResetsMinRequestBodyDataRate ( )
166
152
{
@@ -182,31 +168,73 @@ public void ResetResetsMinResponseDataRate()
182
168
}
183
169
184
170
[ Fact ]
185
- public void TraceIdentifierCountsRequestsPerHttp1Connection ( )
171
+ public async Task TraceIdentifierCountsRequestsPerHttp1Connection ( )
186
172
{
187
173
var connectionId = _http1ConnectionContext . ConnectionId ;
188
174
var feature = ( ( IFeatureCollection ) _http1Connection ) . Get < IHttpRequestIdentifierFeature > ( ) ;
189
- // Reset() is called once in the test ctor
175
+
176
+ var requestProcessingTask = _http1Connection . ProcessRequestsAsync ( new DummyApplication ( ) ) ;
177
+
190
178
var count = 1 ;
191
- void Reset ( )
179
+ async Task SendRequestAsync ( )
192
180
{
193
- _http1Connection . Reset ( ) ;
181
+ var data = Encoding . ASCII . GetBytes ( "GET / HTTP/1.1\r \n Host:\r \n \r \n " ) ;
182
+ await _application . Output . WriteAsync ( data ) ;
183
+
184
+ while ( true )
185
+ {
186
+ var read = await _application . Input . ReadAsync ( ) ;
187
+ SequencePosition consumed = read . Buffer . Start ;
188
+ SequencePosition examined = read . Buffer . End ;
189
+ try
190
+ {
191
+ if ( TryReadResponse ( read , out consumed , out examined ) )
192
+ {
193
+ break ;
194
+ }
195
+ }
196
+ finally
197
+ {
198
+ _application . Input . AdvanceTo ( consumed , examined ) ;
199
+ }
200
+ }
201
+
194
202
count ++ ;
195
203
}
196
204
197
205
var nextId = feature . TraceIdentifier ;
198
206
Assert . Equal ( $ "{ connectionId } :00000001", nextId ) ;
199
207
200
- Reset ( ) ;
208
+ await SendRequestAsync ( ) ;
209
+
201
210
var secondId = feature . TraceIdentifier ;
202
211
Assert . Equal ( $ "{ connectionId } :00000002", secondId ) ;
203
212
204
- var big = 1_000_000 ;
213
+ var big = 10_000 ;
205
214
while ( big -- > 0 )
206
215
{
207
- Reset ( ) ;
216
+ await SendRequestAsync ( ) ;
208
217
}
209
218
Assert . Equal ( $ "{ connectionId } :{ count : X8} ", feature . TraceIdentifier ) ;
219
+
220
+ _http1Connection . StopProcessingNextRequest ( ) ;
221
+ await requestProcessingTask . DefaultTimeout ( ) ;
222
+ }
223
+
224
+ private static bool TryReadResponse ( ReadResult read , out SequencePosition consumed , out SequencePosition examined )
225
+ {
226
+ consumed = read . Buffer . Start ;
227
+ examined = read . Buffer . End ;
228
+
229
+ SequenceReader < byte > reader = new SequenceReader < byte > ( read . Buffer ) ;
230
+ if ( reader . TryReadTo ( out ReadOnlySequence < byte > _ , new byte [ ] { ( byte ) '\r ' , ( byte ) '\n ' , ( byte ) '\r ' , ( byte ) '\n ' } , advancePastDelimiter : true ) )
231
+ {
232
+ consumed = reader . Position ;
233
+ examined = reader . Position ;
234
+ return true ;
235
+ }
236
+
237
+ return false ;
210
238
}
211
239
212
240
[ Fact ]
@@ -216,9 +244,6 @@ public void TraceIdentifierGeneratesWhenNull()
216
244
var id = _http1Connection . TraceIdentifier ;
217
245
Assert . NotNull ( id ) ;
218
246
Assert . Equal ( id , _http1Connection . TraceIdentifier ) ;
219
-
220
- _http1Connection . Reset ( ) ;
221
- Assert . NotEqual ( id , _http1Connection . TraceIdentifier ) ;
222
247
}
223
248
224
249
[ Fact ]
0 commit comments