Skip to content

Commit

Permalink
test(NODE-4139): test for different last doc
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed May 23, 2022
1 parent 9621129 commit 71fd458
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cmap/message_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function processIncomingData(stream: MessageStream, callback: Callback<Buffer>)
// Can we read the next message size?
if (buffer.length >= 4) {
const sizeOfMessage = buffer.peek(4).readInt32LE();
if (sizeOfMessage < buffer.length) {
if (sizeOfMessage <= buffer.length) {
return true;
}
}
Expand Down
7 changes: 4 additions & 3 deletions test/unit/cmap/message_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function bufferToStream(buffer) {
describe('MessageStream', function () {
context('when the stream is for a monitoring connection', function () {
const response = { isWritablePrimary: true };
const lastResponse = { ok: 1 };
let firstHello;
let secondHello;
let thirdHello;
Expand All @@ -31,7 +32,7 @@ describe('MessageStream', function () {
beforeEach(function () {
firstHello = generateOpMsgBuffer(response);
secondHello = generateOpMsgBuffer(response);
thirdHello = generateOpMsgBuffer(response);
thirdHello = generateOpMsgBuffer(lastResponse);
partial = Buffer.alloc(5);
partial.writeInt32LE(100, 0);
});
Expand All @@ -45,7 +46,7 @@ describe('MessageStream', function () {
const messages = await once(messageStream, 'message');
const msg = messages[0];
msg.parse();
expect(msg).to.have.property('documents').that.deep.equals([response]);
expect(msg).to.have.property('documents').that.deep.equals([lastResponse]);
// Make sure there is nothing left in the buffer.
expect(messageStream.buffer.length).to.equal(0);
});
Expand All @@ -61,7 +62,7 @@ describe('MessageStream', function () {
const messages = await once(messageStream, 'message');
const msg = messages[0];
msg.parse();
expect(msg).to.have.property('documents').that.deep.equals([response]);
expect(msg).to.have.property('documents').that.deep.equals([lastResponse]);
// Make sure the buffer wasn't read to the end.
expect(messageStream.buffer.length).to.equal(5);
});
Expand Down

0 comments on commit 71fd458

Please sign in to comment.