@@ -22,17 +22,27 @@ import {
22
22
MongoServerError
23
23
} from '../../mongodb' ;
24
24
import { type FailPoint } from '../../tools/utils' ;
25
+ import { on } from 'node:events' ;
25
26
26
27
const metadata = { requires : { mongodb : '>=4.4' } } ;
27
28
29
+
28
30
describe ( 'CSOT driver tests' , metadata , ( ) => {
31
+ const minPoolSize = 20 ;
32
+ async function ensurePoolIsFull ( client : MongoClient ) {
33
+ let connectionCount = 0 ;
34
+ for await ( const _ of on ( client , 'connectionCreated' ) ) {
35
+ if ( connectionCount ++ >= minPoolSize ) break ;
36
+ }
37
+ }
38
+
29
39
describe ( 'timeoutMS inheritance' , ( ) => {
30
40
let client : MongoClient ;
31
41
let db : Db ;
32
42
let coll : Collection ;
33
43
34
44
beforeEach ( async function ( ) {
35
- client = this . configuration . newClient ( undefined , { timeoutMS : 100 } ) ;
45
+ client = this . configuration . newClient ( undefined , { timeoutMS : 100 , minPoolSize } ) ;
36
46
db = client . db ( 'test' , { timeoutMS : 200 } ) ;
37
47
} ) ;
38
48
@@ -576,7 +586,7 @@ describe('CSOT driver tests', metadata, () => {
576
586
} ) ;
577
587
} ) ;
578
588
579
- describe ( 'Tailable cursors' , function ( ) {
589
+ describe . only ( 'Tailable cursors' , function ( ) {
580
590
let client : MongoClient ;
581
591
let internalClient : MongoClient ;
582
592
let commandStarted : CommandStartedEvent [ ] ;
@@ -611,9 +621,10 @@ describe('CSOT driver tests', metadata, () => {
611
621
612
622
await internalClient . db ( ) . admin ( ) . command ( failpoint ) ;
613
623
614
- client = this . configuration . newClient ( undefined , { monitorCommands : true } ) ;
624
+ client = this . configuration . newClient ( undefined , { monitorCommands : true , minPoolSize } ) ;
615
625
commandStarted = [ ] ;
616
626
client . on ( 'commandStarted' , ev => commandStarted . push ( ev ) ) ;
627
+ await client . connect ( ) ;
617
628
} ) ;
618
629
619
630
afterEach ( async function ( ) {
@@ -739,9 +750,10 @@ describe('CSOT driver tests', metadata, () => {
739
750
740
751
await cursor . next ( ) ;
741
752
742
- expect ( commandStarted ) . to . have . lengthOf ( 1 ) ;
743
- expect ( commandStarted [ 0 ] . command . find ) . to . exist ;
744
- expect ( commandStarted [ 0 ] . command . maxTimeMS ) . to . not . exist ;
753
+ const finds = commandStarted . filter ( x => x . command . find != null ) ;
754
+ expect ( finds ) . to . have . lengthOf ( 1 ) ;
755
+ expect ( finds [ 0 ] . command . find ) . to . exist ;
756
+ expect ( finds [ 0 ] . command . maxTimeMS ) . to . not . exist ;
745
757
} ) ;
746
758
it ( 'does not append a maxTimeMS field to subsequent getMores' , async function ( ) {
747
759
cursor = client
@@ -752,9 +764,11 @@ describe('CSOT driver tests', metadata, () => {
752
764
await cursor . next ( ) ;
753
765
await cursor . next ( ) ;
754
766
755
- expect ( commandStarted ) . to . have . lengthOf ( 2 ) ;
756
- expect ( commandStarted [ 1 ] . command . getMore ) . to . exist ;
757
- expect ( commandStarted [ 0 ] . command . maxTimeMS ) . to . not . exist ;
767
+ const getMores = commandStarted . filter ( x => x . command . getMore != null ) ;
768
+
769
+ expect ( getMores ) . to . have . lengthOf ( 1 ) ;
770
+ expect ( getMores [ 0 ] . command . getMore ) . to . exist ;
771
+ expect ( getMores [ 0 ] . command . getMore . maxTimeMS ) . to . not . exist ;
758
772
} ) ;
759
773
} ) ;
760
774
} ) ;
0 commit comments