@@ -11,7 +11,8 @@ import {
1111 MongoClientAuthProviders ,
1212 MongoDBCollectionNamespace ,
1313 MongoNetworkTimeoutError ,
14- ns
14+ ns ,
15+ SizedMessageTransform
1516} from '../../mongodb' ;
1617import * as mock from '../../tools/mongodb-mock/index' ;
1718import { getSymbolFrom } from '../../tools/utils' ;
@@ -323,4 +324,19 @@ describe('new Connection()', function () {
323324 } ) ;
324325 } ) ;
325326 } ) ;
327+
328+ describe ( 'SizedMessageTransform' , function ( ) {
329+ it ( 'parses chunks of wire messages' , function ( ) {
330+ const stream = new SizedMessageTransform ( { connection : { } as any } ) ;
331+ // Message of length 4 + 4 = 8
332+ stream . write ( Buffer . from ( [ 8 , 0 , 0 , 0 ] ) ) ;
333+ stream . write ( Buffer . from ( [ 1 , 2 , 3 , 4 ] ) ) ;
334+ // Message of length 4 + 2 = 6, chunked differently
335+ stream . write ( Buffer . from ( [ 6 , 0 , 0 ] ) ) ;
336+ stream . write ( Buffer . from ( [ 0 , 5 , 6 ] ) ) ;
337+ expect ( stream . read ( 1 ) ) . to . deep . equal ( Buffer . from ( [ 8 , 0 , 0 , 0 , 1 , 2 , 3 , 4 ] ) ) ;
338+ expect ( stream . read ( 1 ) ) . to . deep . equal ( Buffer . from ( [ 6 , 0 , 0 , 0 , 5 , 6 ] ) ) ;
339+ expect ( stream . read ( 1 ) ) . to . equal ( null ) ;
340+ } ) ;
341+ } ) ;
326342} ) ;
0 commit comments