@@ -8,11 +8,11 @@ import {
8
8
type Document ,
9
9
type MongoClient ,
10
10
MongoOperationTimeoutError ,
11
- MongoServerError
11
+ MongoServerError ,
12
+ squashError
12
13
} from '../../mongodb' ;
13
14
import { clearFailPoint , configureFailPoint , measureDuration } from '../../tools/utils' ;
14
15
import { filterForCommands } from '../shared' ;
15
- import { clear } from 'console' ;
16
16
17
17
const explain = [ true , false , 'queryPlanner' , 'allPlansExecution' , 'executionStats' , 'invalid' ] ;
18
18
@@ -326,7 +326,7 @@ describe('CRUD API explain option', function () {
326
326
data : {
327
327
failCommands : [ 'explain' ] ,
328
328
blockConnection : true ,
329
- blockTimeMS : 1000
329
+ blockTimeMS : 2000
330
330
}
331
331
} ,
332
332
this . configuration . url ( { useMultipleMongoses : false } )
@@ -565,13 +565,15 @@ describe('CRUD API explain option', function () {
565
565
}
566
566
) ;
567
567
} ) ;
568
- } )
568
+ } ) ;
569
569
570
570
describe ( 'fluent api timeoutMS precedence and inheritance' , function ( ) {
571
571
beforeEach ( async function ( ) {
572
572
client = this . configuration . newClient ( { } , { monitorCommands : true } ) ;
573
573
client . on ( 'commandStarted' , filterForCommands ( 'explain' , commands ) ) ;
574
574
await client . connect ( ) ;
575
+ await client . db ( 'foo' ) . dropDatabase ( ) . catch ( squashError ) ;
576
+ await client . db ( 'foo' ) . createCollection ( 'bar' ) ;
575
577
} ) ;
576
578
577
579
afterEach ( async function ( ) {
@@ -601,7 +603,8 @@ describe('CRUD API explain option', function () {
601
603
expect ( maxTimeMS ) . not . to . exist ;
602
604
commands . length = 0 ;
603
605
}
604
- } )
606
+ } ) ;
607
+
605
608
beforeEach ( 'aggregate does not set maxTimeMS if timeoutMS is not set' , async function ( ) {
606
609
{
607
610
const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . aggregate ( [ ] ) ;
@@ -615,108 +618,90 @@ describe('CRUD API explain option', function () {
615
618
expect ( maxTimeMS ) . not . to . exist ;
616
619
commands . length = 0 ;
617
620
}
618
- } )
621
+ } ) ;
619
622
} ) ;
620
623
621
624
describe ( 'find({}, { timeoutMS }).explain()' , function ( ) {
622
- it (
623
- 'respects the timeoutMS from the find options' ,
624
- async function ( ) {
625
- const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . find ( { } , { timeoutMS : 800 } ) ;
626
- await cursor . explain ( { verbosity : 'queryPlanner' } ) ;
625
+ it ( 'respects the timeoutMS from the find options' , async function ( ) {
626
+ const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . find ( { } , { timeoutMS : 800 } ) ;
627
+ await cursor . explain ( { verbosity : 'queryPlanner' } ) ;
627
628
628
- const [
629
- {
630
- command : { maxTimeMS }
631
- }
632
- ] = commands ;
633
- expect ( maxTimeMS ) . to . exist ;
634
- }
635
- ) ;
629
+ const [
630
+ {
631
+ command : { maxTimeMS }
632
+ }
633
+ ] = commands ;
634
+ expect ( maxTimeMS ) . to . exist ;
635
+ } ) ;
636
636
} ) ;
637
637
638
638
describe ( 'find().explain({}, { timeoutMS })' , function ( ) {
639
- it (
640
- 'respects the timeoutMS from the explain helper' ,
641
- async function ( ) {
642
- const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . find ( ) ;
643
- await cursor . explain ( { verbosity : 'queryPlanner' } , { timeoutMS : 800 } )
639
+ it ( 'respects the timeoutMS from the explain helper' , async function ( ) {
640
+ const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . find ( ) ;
641
+ await cursor . explain ( { verbosity : 'queryPlanner' } , { timeoutMS : 800 } ) ;
644
642
645
- const [
646
- {
647
- command : { maxTimeMS }
648
- }
649
- ] = commands ;
650
- expect ( maxTimeMS ) . to . exist ;
651
- }
652
- ) ;
643
+ const [
644
+ {
645
+ command : { maxTimeMS }
646
+ }
647
+ ] = commands ;
648
+ expect ( maxTimeMS ) . to . exist ;
649
+ } ) ;
653
650
} ) ;
654
651
655
652
describe ( 'find({}, { timeoutMS} ).explain({}, { timeoutMS })' , function ( ) {
656
- it (
657
- 'the timeoutMS from the explain helper has precedence' ,
658
- async function ( ) {
659
- const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . find ( { } , { timeoutMS : 100 } ) ;
660
- await cursor . explain ( { verbosity : 'queryPlanner' } , { timeoutMS : 800 } ) ;
661
- const [
662
- {
663
- command : { maxTimeMS }
664
- }
665
- ] = commands ;
666
- expect ( maxTimeMS ) . to . exist ;
667
- expect ( maxTimeMS ) . to . be . greaterThan ( 100 ) ;
668
- }
669
- ) ;
653
+ it ( 'the timeoutMS from the explain helper has precedence' , async function ( ) {
654
+ const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . find ( { } , { timeoutMS : 100 } ) ;
655
+ await cursor . explain ( { verbosity : 'queryPlanner' } , { timeoutMS : 800 } ) ;
656
+ const [
657
+ {
658
+ command : { maxTimeMS }
659
+ }
660
+ ] = commands ;
661
+ expect ( maxTimeMS ) . to . exist ;
662
+ expect ( maxTimeMS ) . to . be . greaterThan ( 100 ) ;
663
+ } ) ;
670
664
} ) ;
671
665
672
666
describe ( 'aggregate([], { timeoutMS }).explain()' , function ( ) {
673
- it (
674
- 'respects the timeoutMS from the find options' ,
675
- async function ( ) {
676
- const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . aggregate ( [ ] , { timeoutMS : 800 } ) ;
677
- await cursor . explain ( { verbosity : 'queryPlanner' } )
667
+ it ( 'respects the timeoutMS from the find options' , async function ( ) {
668
+ const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . aggregate ( [ ] , { timeoutMS : 800 } ) ;
669
+ await cursor . explain ( { verbosity : 'queryPlanner' } ) ;
678
670
679
- const [
680
- {
681
- command : { maxTimeMS }
682
- }
683
- ] = commands ;
684
- expect ( maxTimeMS ) . to . exist ;
685
- }
686
- ) ;
671
+ const [
672
+ {
673
+ command : { maxTimeMS }
674
+ }
675
+ ] = commands ;
676
+ expect ( maxTimeMS ) . to . exist ;
677
+ } ) ;
687
678
} ) ;
688
679
689
680
describe ( 'aggregate([], { timeoutMS })' , function ( ) {
690
- it (
691
- 'respects the timeoutMS from the explain helper' ,
692
- async function ( ) {
693
- const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . aggregate ( ) ;
694
- await cursor . explain ( { verbosity : 'queryPlanner' } , { timeoutMS : 800 } )
695
- const [
696
- {
697
- command : { maxTimeMS }
698
- }
699
- ] = commands ;
700
- expect ( maxTimeMS ) . to . exist ;
701
- }
702
- ) ;
681
+ it ( 'respects the timeoutMS from the explain helper' , async function ( ) {
682
+ const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . aggregate ( ) ;
683
+ await cursor . explain ( { verbosity : 'queryPlanner' } , { timeoutMS : 800 } ) ;
684
+ const [
685
+ {
686
+ command : { maxTimeMS }
687
+ }
688
+ ] = commands ;
689
+ expect ( maxTimeMS ) . to . exist ;
690
+ } ) ;
703
691
} ) ;
704
692
705
693
describe ( 'aggregate([], { timeoutMS} ).explain({}, { timeoutMS })' , function ( ) {
706
- it (
707
- 'the timeoutMS from the explain helper has precedence' ,
708
- async function ( ) {
709
- const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . aggregate ( [ ] , { timeoutMS : 100 } ) ;
710
- await cursor . explain ( { verbosity : 'queryPlanner' } , { timeoutMS : 800 } )
711
- const [
712
- {
713
- command : { maxTimeMS }
714
- }
715
- ] = commands ;
716
- expect ( maxTimeMS ) . to . exist ;
717
- expect ( maxTimeMS ) . to . be . greaterThan ( 100 ) ;
718
- }
719
- ) ;
694
+ it ( 'the timeoutMS from the explain helper has precedence' , async function ( ) {
695
+ const cursor = client . db ( 'foo' ) . collection ( 'bar' ) . aggregate ( [ ] , { timeoutMS : 100 } ) ;
696
+ await cursor . explain ( { verbosity : 'queryPlanner' } , { timeoutMS : 800 } ) ;
697
+ const [
698
+ {
699
+ command : { maxTimeMS }
700
+ }
701
+ ] = commands ;
702
+ expect ( maxTimeMS ) . to . exist ;
703
+ expect ( maxTimeMS ) . to . be . greaterThan ( 100 ) ;
704
+ } ) ;
720
705
} ) ;
721
706
} ) ;
722
707
} ) ;
0 commit comments