1
1
'use strict' ;
2
2
3
- var fs = require ( 'fs' ) ,
3
+ const fs = require ( 'fs' ) ,
4
4
path = require ( 'path' ) ,
5
5
expect = require ( 'chai' ) . expect ;
6
6
7
7
let testContext = { } ;
8
8
describe ( 'Retryable Writes' , function ( ) {
9
9
before ( function ( ) {
10
- var configuration = this . configuration ;
11
- var MongoClient = configuration . require . MongoClient ;
12
- return MongoClient . connect ( configuration . url ( ) ) . then ( function ( client ) {
10
+ const configuration = this . configuration ;
11
+ const MongoClient = configuration . require . MongoClient ;
12
+ const url = `${ configuration . url ( ) } &retryWrites=true` ;
13
+
14
+ return MongoClient . connect ( url , { minSize : 1 } ) . then ( function ( client ) {
13
15
testContext . client = client ;
14
16
testContext . db = client . db ( configuration . db ) ;
15
17
} ) ;
@@ -30,32 +32,32 @@ describe('Retryable Writes', function() {
30
32
31
33
describe ( methodName , function ( ) {
32
34
scenario . tests . forEach ( test => {
33
- beforeEach ( function ( ) {
34
- if ( test . failpoint ) {
35
- return testContext . db . command ( {
36
- configureFailPoint : 'onPrimaryTransactionalWrite' ,
37
- mode : test . failpoint . mode ,
38
- data : test . failpoint . data
39
- } ) ;
40
- }
41
- } ) ;
42
-
43
- afterEach ( function ( ) {
44
- if ( test . failpoint ) {
45
- return testContext . db . command ( {
46
- configureFailPoint : 'onPrimaryTransactionalWrite' ,
47
- mode : 'off'
48
- } ) ;
49
- }
50
- } ) ;
51
-
52
35
it ( test . description , {
53
36
metadata : {
54
37
requires : { topology : [ 'single' ] , mongodb : '>=' + scenario . minServerVersion }
55
38
} ,
56
39
57
40
test : function ( ) {
58
- return executeScenarioTest ( scenario , test , this . configuration , testContext ) ;
41
+ let setupPromise ;
42
+ if ( test . failPoint ) {
43
+ const command = { configureFailPoint : 'onPrimaryTransactionalWrite' } ;
44
+ if ( test . failPoint . mode ) command . mode = test . failPoint . mode ;
45
+ if ( test . failPoint . data ) command . data = test . failPoint . data ;
46
+ return testContext . db . executeDbAdminCommand ( command ) ;
47
+ } else {
48
+ setupPromise = Promise . resolve ( ) ;
49
+ }
50
+
51
+ return setupPromise
52
+ . then ( ( ) => executeScenarioTest ( scenario , test , this . configuration , testContext ) )
53
+ . then ( ( ) => {
54
+ if ( test . failPoint ) {
55
+ return testContext . db . executeDbAdminCommand ( {
56
+ configureFailPoint : 'onPrimaryTransactionalWrite' ,
57
+ mode : 'off'
58
+ } ) ;
59
+ }
60
+ } ) ;
59
61
}
60
62
} ) ;
61
63
} ) ;
@@ -70,7 +72,7 @@ const convertBulkWriteOperation = op => {
70
72
} ;
71
73
72
74
function executeScenarioTest ( scenario , test , configuration , context ) {
73
- var collection = context . db . collection (
75
+ const collection = context . db . collection (
74
76
'retryable_writes_test_' + scenario . name + '_' + test . operation . name
75
77
) ;
76
78
@@ -104,7 +106,10 @@ function executeScenarioTest(scenario, test, configuration, context) {
104
106
105
107
let result = collection [ test . operation . name ] . apply ( collection , args ) ;
106
108
if ( test . outcome . error ) {
107
- result = result . then ( ( ) => expect ( false ) . to . be . true ) . catch ( err => expect ( err ) . to . exist ) ;
109
+ result = result . then ( ( ) => expect ( false ) . to . be . true ) . catch ( err => {
110
+ expect ( err ) . to . exist ;
111
+ expect ( err . message ) . to . not . match ( / e x p e c t e d f a l s e t o b e t r u e / ) ;
112
+ } ) ;
108
113
} else if ( test . outcome . result ) {
109
114
result = result . then ( r => expect ( r ) . to . deep . include ( test . outcome . result ) ) ;
110
115
}
@@ -116,7 +121,7 @@ function executeScenarioTest(scenario, test, configuration, context) {
116
121
return collection
117
122
. find ( { } )
118
123
. toArray ( )
119
- . then ( function ( collectionResults ) {
124
+ . then ( collectionResults => {
120
125
expect ( collectionResults ) . to . eql ( test . outcome . collection . data ) ;
121
126
} ) ;
122
127
}
0 commit comments