Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -384,7 +384,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
} else {
// Get the first orphaned operation description.
const entry = this[kQueue].entries().next();
if (entry) {
if (entry.value != null) {
const [requestId, orphaned]: [number, OperationDescription] = entry.value;
// If the orphaned operation description exists then set it.
operationDescription = orphaned;
Expand Down
28 changes: 28 additions & 0 deletions test/unit/cmap/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,34 @@ describe('new Connection()', function () {
});
});

context('when no operation description is in the queue', function () {
const document = { ok: 1 };

beforeEach(function () {
// @ts-expect-error: driverSocket does not fully satisfy the stream type, but that's okay
connection = sinon.spy(new Connection(driverSocket, connectionOptionsDefaults));
connection.isMonitoringConnection = true;
const queueSymbol = getSymbolFrom(connection, 'queue');
queue = connection[queueSymbol];
});

it('does not error', function () {
const msg = generateOpMsgBuffer(document);
const msgHeader: MessageHeader = {
length: msg.readInt32LE(0),
requestId: 2,
responseTo: 1,
opCode: msg.readInt32LE(12)
};
const msgBody = msg.subarray(16);

const message = new BinMsg(msg, msgHeader, msgBody);
expect(() => {
connection.onMessage(message);
}).to.not.throw();
});
});

context('when more than one operation description is in the queue', function () {
let spyOne;
let spyTwo;
Expand Down