@@ -323,7 +323,7 @@ describe('new Connection()', function () {
323
323
} ) ;
324
324
} ) ;
325
325
326
- describe ( 'SizedMessageTransform' , function ( ) {
326
+ describe . only ( 'SizedMessageTransform' , function ( ) {
327
327
it ( 'parses chunks of wire messages' , function ( ) {
328
328
const stream = new SizedMessageTransform ( { connection : { } as any } ) ;
329
329
// Message of length 4 + 4 = 8
@@ -337,7 +337,7 @@ describe('new Connection()', function () {
337
337
expect ( stream . read ( 1 ) ) . to . equal ( null ) ;
338
338
} ) ;
339
339
340
- it ( 'parses many wire messages when chunk arrives' , function ( ) {
340
+ it ( 'parses many wire messages when a single chunk arrives' , function ( ) {
341
341
const stream = new SizedMessageTransform ( { connection : { } as any } ) ;
342
342
343
343
let dataCount = 0 ;
@@ -357,7 +357,32 @@ describe('new Connection()', function () {
357
357
expect ( dataCount ) . to . equal ( 3 ) ;
358
358
} ) ;
359
359
360
- it ( 'waits for a drain event when destination needs backpressure' , async function ( ) {
360
+ it ( 'parses many wire messages when a single chunk arrives and processes the remaining partial when it is complete' , function ( ) {
361
+ const stream = new SizedMessageTransform ( { connection : { } as any } ) ;
362
+
363
+ let dataCount = 0 ;
364
+ stream . on ( 'data' , ( ) => {
365
+ dataCount += 1 ;
366
+ } ) ;
367
+
368
+ // 3 messages of size 8
369
+ stream . write (
370
+ Buffer . from ( [
371
+ ...[ 8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
372
+ ...[ 8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
373
+ ...[ 8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
374
+ ...[ 8 , 0 , 0 , 0 , 0 , 0 ] // two shy of 8
375
+ ] )
376
+ ) ;
377
+
378
+ expect ( dataCount ) . to . equal ( 3 ) ;
379
+
380
+ stream . write ( Buffer . from ( [ 0 , 0 ] ) ) ; // the rest of the last 8
381
+
382
+ expect ( dataCount ) . to . equal ( 4 ) ;
383
+ } ) ;
384
+
385
+ it ( 'throws an error when backpressure detected' , async function ( ) {
361
386
const stream = new SizedMessageTransform ( { connection : { } as any } ) ;
362
387
const destination = new Writable ( {
363
388
highWaterMark : 1 ,
0 commit comments