@@ -11,7 +11,8 @@ import {
11
11
MongoClientAuthProviders ,
12
12
MongoDBCollectionNamespace ,
13
13
MongoNetworkTimeoutError ,
14
- ns
14
+ ns ,
15
+ SizedMessageTransform
15
16
} from '../../mongodb' ;
16
17
import * as mock from '../../tools/mongodb-mock/index' ;
17
18
import { getSymbolFrom } from '../../tools/utils' ;
@@ -323,4 +324,19 @@ describe('new Connection()', function () {
323
324
} ) ;
324
325
} ) ;
325
326
} ) ;
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
+ } ) ;
326
342
} ) ;
0 commit comments