File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -384,7 +384,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
384
384
} else {
385
385
// Get the first orphaned operation description.
386
386
const entry = this [ kQueue ] . entries ( ) . next ( ) ;
387
- if ( entry ) {
387
+ if ( entry . value != null ) {
388
388
const [ requestId , orphaned ] : [ number , OperationDescription ] = entry . value ;
389
389
// If the orphaned operation description exists then set it.
390
390
operationDescription = orphaned ;
Original file line number Diff line number Diff line change @@ -287,6 +287,34 @@ describe('new Connection()', function () {
287
287
} ) ;
288
288
} ) ;
289
289
290
+ context ( 'when no operation description is in the queue' , function ( ) {
291
+ const document = { ok : 1 } ;
292
+
293
+ beforeEach ( function ( ) {
294
+ // @ts -expect-error: driverSocket does not fully satisfy the stream type, but that's okay
295
+ connection = sinon . spy ( new Connection ( driverSocket , connectionOptionsDefaults ) ) ;
296
+ connection . isMonitoringConnection = true ;
297
+ const queueSymbol = getSymbolFrom ( connection , 'queue' ) ;
298
+ queue = connection [ queueSymbol ] ;
299
+ } ) ;
300
+
301
+ it ( 'does not error' , function ( ) {
302
+ const msg = generateOpMsgBuffer ( document ) ;
303
+ const msgHeader : MessageHeader = {
304
+ length : msg . readInt32LE ( 0 ) ,
305
+ requestId : 2 ,
306
+ responseTo : 1 ,
307
+ opCode : msg . readInt32LE ( 12 )
308
+ } ;
309
+ const msgBody = msg . subarray ( 16 ) ;
310
+
311
+ const message = new BinMsg ( msg , msgHeader , msgBody ) ;
312
+ expect ( ( ) => {
313
+ connection . onMessage ( message ) ;
314
+ } ) . to . not . throw ( ) ;
315
+ } ) ;
316
+ } ) ;
317
+
290
318
context ( 'when more than one operation description is in the queue' , function ( ) {
291
319
let spyOne ;
292
320
let spyTwo ;
You can’t perform that action at this time.
0 commit comments