Skip to content

Commit 71fd458

Browse files
committed
test(NODE-4139): test for different last doc
1 parent 9621129 commit 71fd458

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/cmap/message_stream.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function processIncomingData(stream: MessageStream, callback: Callback<Buffer>)
173173
// Can we read the next message size?
174174
if (buffer.length >= 4) {
175175
const sizeOfMessage = buffer.peek(4).readInt32LE();
176-
if (sizeOfMessage < buffer.length) {
176+
if (sizeOfMessage <= buffer.length) {
177177
return true;
178178
}
179179
}

test/unit/cmap/message_stream.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function bufferToStream(buffer) {
2323
describe('MessageStream', function () {
2424
context('when the stream is for a monitoring connection', function () {
2525
const response = { isWritablePrimary: true };
26+
const lastResponse = { ok: 1 };
2627
let firstHello;
2728
let secondHello;
2829
let thirdHello;
@@ -31,7 +32,7 @@ describe('MessageStream', function () {
3132
beforeEach(function () {
3233
firstHello = generateOpMsgBuffer(response);
3334
secondHello = generateOpMsgBuffer(response);
34-
thirdHello = generateOpMsgBuffer(response);
35+
thirdHello = generateOpMsgBuffer(lastResponse);
3536
partial = Buffer.alloc(5);
3637
partial.writeInt32LE(100, 0);
3738
});
@@ -45,7 +46,7 @@ describe('MessageStream', function () {
4546
const messages = await once(messageStream, 'message');
4647
const msg = messages[0];
4748
msg.parse();
48-
expect(msg).to.have.property('documents').that.deep.equals([response]);
49+
expect(msg).to.have.property('documents').that.deep.equals([lastResponse]);
4950
// Make sure there is nothing left in the buffer.
5051
expect(messageStream.buffer.length).to.equal(0);
5152
});
@@ -61,7 +62,7 @@ describe('MessageStream', function () {
6162
const messages = await once(messageStream, 'message');
6263
const msg = messages[0];
6364
msg.parse();
64-
expect(msg).to.have.property('documents').that.deep.equals([response]);
65+
expect(msg).to.have.property('documents').that.deep.equals([lastResponse]);
6566
// Make sure the buffer wasn't read to the end.
6667
expect(messageStream.buffer.length).to.equal(5);
6768
});

0 commit comments

Comments
 (0)