@@ -7,8 +7,66 @@ const { TestRunnerContext, generateTopologyTests } = require('./spec-runner');
7
7
const { loadSpecTests } = require ( '../spec' ) ;
8
8
const { MongoNetworkError } = require ( '../../lib/error' ) ;
9
9
10
+ function ignoreNsNotFoundForListIndexes ( err ) {
11
+ if ( err . code !== 26 ) {
12
+ throw err ;
13
+ }
14
+
15
+ return [ ] ;
16
+ }
17
+
18
+ class TransactionsRunnerContext extends TestRunnerContext {
19
+ assertCollectionExists ( options ) {
20
+ const client = this . sharedClient ;
21
+ const db = client . db ( options . database ) ;
22
+ const collectionName = options . collection ;
23
+
24
+ return db
25
+ . listCollections ( )
26
+ . toArray ( )
27
+ . then ( collections => expect ( collections . some ( coll => coll . name === collectionName ) ) . to . be . ok ) ;
28
+ }
29
+
30
+ assertCollectionNotExists ( options ) {
31
+ const client = this . sharedClient ;
32
+ const db = client . db ( options . database ) ;
33
+ const collectionName = options . collection ;
34
+
35
+ return db
36
+ . listCollections ( )
37
+ . toArray ( )
38
+ . then (
39
+ collections => expect ( collections . every ( coll => coll . name !== collectionName ) ) . to . be . ok
40
+ ) ;
41
+ }
42
+
43
+ assertIndexExists ( options ) {
44
+ const client = this . sharedClient ;
45
+ const collection = client . db ( options . database ) . collection ( options . collection ) ;
46
+ const indexName = options . index ;
47
+
48
+ return collection
49
+ . listIndexes ( )
50
+ . toArray ( )
51
+ . catch ( ignoreNsNotFoundForListIndexes )
52
+ . then ( indexes => expect ( indexes . some ( idx => idx . name === indexName ) ) . to . be . ok ) ;
53
+ }
54
+
55
+ assertIndexNotExists ( options ) {
56
+ const client = this . sharedClient ;
57
+ const collection = client . db ( options . database ) . collection ( options . collection ) ;
58
+ const indexName = options . index ;
59
+
60
+ return collection
61
+ . listIndexes ( )
62
+ . toArray ( )
63
+ . catch ( ignoreNsNotFoundForListIndexes )
64
+ . then ( indexes => expect ( indexes . every ( idx => idx . name !== indexName ) ) . to . be . ok ) ;
65
+ }
66
+ }
67
+
10
68
describe ( 'Transactions' , function ( ) {
11
- const testContext = new TestRunnerContext ( ) ;
69
+ const testContext = new TransactionsRunnerContext ( ) ;
12
70
13
71
[
14
72
{ name : 'spec tests' , specPath : 'transactions' } ,
@@ -34,7 +92,17 @@ describe('Transactions', function() {
34
92
// This test needs there to be multiple mongoses
35
93
'increment txnNumber' ,
36
94
// Skipping this until SPEC-1320 is resolved
37
- 'remain pinned after non-transient error on commit'
95
+ 'remain pinned after non-transient error on commit' ,
96
+
97
+ // Will be implemented as part of NODE-2034
98
+ 'Client side error in command starting transaction' ,
99
+ 'Client side error when transaction is in progress' ,
100
+
101
+ // Will be implemented as part of NODE-2538
102
+ 'abortTransaction only retries once with RetryableWriteError from server' ,
103
+ 'abortTransaction does not retry without RetryableWriteError label' ,
104
+ 'commitTransaction does not retry error without RetryableWriteError label' ,
105
+ 'commitTransaction retries once with RetryableWriteError from server'
38
106
] ;
39
107
40
108
return SKIP_TESTS . indexOf ( spec . description ) === - 1 ;
@@ -132,7 +200,7 @@ describe('Transactions', function() {
132
200
133
201
const session = client . startSession ( ) ;
134
202
const db = client . db ( configuration . db ) ;
135
- db . createCollection ( 'transaction_error_test ' , ( err , coll ) => {
203
+ db . createCollection ( 'transaction_error_test_2 ' , ( err , coll ) => {
136
204
expect ( err ) . to . not . exist ;
137
205
138
206
session . startTransaction ( ) ;
0 commit comments