@@ -251,5 +251,43 @@ public void ValidWriteByte_ValidReadByte()
251
251
Assert . Equal ( 123 , pair . readablePipe . ReadByte ( ) ) ;
252
252
}
253
253
}
254
+
255
+ [ Theory ]
256
+ [ InlineData ( 5000 , 1 , 1 ) ] // very small buffers
257
+ [ InlineData ( 500 , 21 , 18 ) ] // lots of iterations, with read buffer smaller than write buffer
258
+ [ InlineData ( 500 , 18 , 21 ) ] // lots of iterations, with write buffer smaller than read buffer
259
+ [ InlineData ( 5 , 128000 , 64000 ) ] // very large buffers
260
+ public async Task AsyncReadWriteChain ( int iterations , int writeBufferSize , int readBufferSize )
261
+ {
262
+ var writeBuffer = new byte [ writeBufferSize ] ;
263
+ var readBuffer = new byte [ readBufferSize ] ;
264
+ var rand = new Random ( ) ;
265
+
266
+ using ( ServerClientPair pair = CreateServerClientPair ( ) )
267
+ {
268
+ // Repeatedly and asynchronously write to the writeable pipe and read from the readable pipe,
269
+ // verifying that the correct data made it through.
270
+ for ( int iter = 0 ; iter < iterations ; iter ++ )
271
+ {
272
+ rand . NextBytes ( writeBuffer ) ;
273
+ Task writerTask = pair . writeablePipe . WriteAsync ( writeBuffer , 0 , writeBuffer . Length ) ;
274
+
275
+ int totalRead = 0 ;
276
+ while ( totalRead < writeBuffer . Length )
277
+ {
278
+ int numRead = await pair . readablePipe . ReadAsync ( readBuffer , 0 , readBuffer . Length ) ;
279
+ Assert . True ( numRead > 0 ) ;
280
+ Assert . Equal < byte > (
281
+ new ArraySegment < byte > ( writeBuffer , totalRead , numRead ) ,
282
+ new ArraySegment < byte > ( readBuffer , 0 , numRead ) ) ;
283
+ totalRead += numRead ;
284
+ }
285
+ Assert . Equal ( writeBuffer . Length , totalRead ) ;
286
+
287
+ await writerTask ;
288
+ }
289
+ }
290
+ }
291
+
254
292
}
255
293
}
0 commit comments