Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ export class SizedMessageTransform extends Transform {
connection: Connection;

constructor({ connection }: { connection: Connection }) {
super({ objectMode: false });
super({ writableObjectMode: false, readableObjectMode: true });
this.bufferPool = new BufferPool();
this.connection = connection;
}
Expand Down
18 changes: 17 additions & 1 deletion test/unit/cmap/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
MongoClientAuthProviders,
MongoDBCollectionNamespace,
MongoNetworkTimeoutError,
ns
ns,
SizedMessageTransform
} from '../../mongodb';
import * as mock from '../../tools/mongodb-mock/index';
import { getSymbolFrom } from '../../tools/utils';
Expand Down Expand Up @@ -323,4 +324,19 @@ describe('new Connection()', function () {
});
});
});

describe('SizedMessageTransform', function () {
it('parses chunks of wire messages', function () {
const stream = new SizedMessageTransform({ connection: {} as any });
// Message of length 4 + 4 = 8
stream.write(Buffer.from([8, 0, 0, 0]));
stream.write(Buffer.from([1, 2, 3, 4]));
// Message of length 4 + 2 = 6, chunked differently
stream.write(Buffer.from([6, 0, 0]));
stream.write(Buffer.from([0, 5, 6]));
expect(stream.read(1)).to.deep.equal(Buffer.from([8, 0, 0, 0, 1, 2, 3, 4]));
expect(stream.read(1)).to.deep.equal(Buffer.from([6, 0, 0, 0, 5, 6]));
expect(stream.read(1)).to.equal(null);
});
});
});
Loading