@@ -323,7 +323,7 @@ describe('new Connection()', function () {
323323 } ) ;
324324 } ) ;
325325
326- describe ( 'SizedMessageTransform' , function ( ) {
326+ describe . only ( 'SizedMessageTransform' , function ( ) {
327327 it ( 'parses chunks of wire messages' , function ( ) {
328328 const stream = new SizedMessageTransform ( { connection : { } as any } ) ;
329329 // Message of length 4 + 4 = 8
@@ -337,7 +337,7 @@ describe('new Connection()', function () {
337337 expect ( stream . read ( 1 ) ) . to . equal ( null ) ;
338338 } ) ;
339339
340- it ( 'parses many wire messages when chunk arrives' , function ( ) {
340+ it ( 'parses many wire messages when a single chunk arrives' , function ( ) {
341341 const stream = new SizedMessageTransform ( { connection : { } as any } ) ;
342342
343343 let dataCount = 0 ;
@@ -357,7 +357,32 @@ describe('new Connection()', function () {
357357 expect ( dataCount ) . to . equal ( 3 ) ;
358358 } ) ;
359359
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 ( ) {
361386 const stream = new SizedMessageTransform ( { connection : { } as any } ) ;
362387 const destination = new Writable ( {
363388 highWaterMark : 1 ,
0 commit comments