-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathtransactions.spec.test.js
134 lines (110 loc) · 4.23 KB
/
transactions.spec.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict';
import { gte } from 'semver';
const path = require('path');
const { expect } = require('chai');
const { TestRunnerContext, generateTopologyTests } = require('../../tools/spec-runner');
const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner');
const { loadSpecTests } = require('../../spec');
function ignoreNsNotFoundForListIndexes(err) {
if (err.code !== 26) {
throw err;
}
return [];
}
class TransactionsRunnerContext extends TestRunnerContext {
assertCollectionExists(options) {
const client = this.sharedClient;
const db = client.db(options.database);
const collectionName = options.collection;
return db
.listCollections()
.toArray()
.then(collections => expect(collections.some(coll => coll.name === collectionName)).to.be.ok);
}
assertCollectionNotExists(options) {
const client = this.sharedClient;
const db = client.db(options.database);
const collectionName = options.collection;
return db
.listCollections()
.toArray()
.then(
collections => expect(collections.every(coll => coll.name !== collectionName)).to.be.ok
);
}
assertIndexExists(options) {
const client = this.sharedClient;
const collection = client.db(options.database).collection(options.collection);
const indexName = options.index;
return collection
.listIndexes()
.toArray()
.catch(ignoreNsNotFoundForListIndexes)
.then(indexes => expect(indexes.some(idx => idx.name === indexName)).to.be.ok);
}
assertIndexNotExists(options) {
const client = this.sharedClient;
const collection = client.db(options.database).collection(options.collection);
const indexName = options.index;
return collection
.listIndexes()
.toArray()
.catch(ignoreNsNotFoundForListIndexes)
.then(indexes => expect(indexes.every(idx => idx.name !== indexName)).to.be.ok);
}
assertSessionPinned(options) {
expect(options).to.have.property('session');
const session = options.session;
expect(session.isPinned).to.be.true;
}
assertSessionUnpinned(options) {
expect(options).to.have.property('session');
const session = options.session;
expect(session.isPinned).to.be.false;
}
}
describe('Transactions Spec Unified Tests', function () {
runUnifiedSuite(loadSpecTests(path.join('transactions', 'unified')));
});
const SKIP_TESTS = [
// TODO(NODE-3943): Investigate these commit test failures
// OLD COMMENT: commitTransaction retry seems to be swallowed by mongos in these two cases
'commitTransaction retry fails on new mongos',
'unpin after transient error within a transaction and commit',
// TODO(NODE-2034): Will be implemented as part of NODE-2034
'Client side error in command starting transaction',
'Client side error when transaction is in progress'
];
const LATEST_SKIP_TESTS = [
// TODO(NODE-5855): Unskip Transactions Spec Unified Tests mongos-unpin.unpin
'unpin after TransientTransactionError error on commit',
'unpin on successful abort',
'unpin after non-transient error on abort',
'unpin after TransientTransactionError error on abort'
];
describe('Transactions Spec Legacy Tests', function () {
const testContext = new TransactionsRunnerContext();
if (process.env.SERVERLESS) {
// TODO(NODE-3550): these tests should pass on serverless but currently fail
SKIP_TESTS.push(
'abortTransaction only performs a single retry',
'abortTransaction does not retry after Interrupted',
'abortTransaction does not retry after WriteConcernError Interrupted',
'commitTransaction does not retry error without RetryableWriteError label',
'commitTransaction is not retried after UnsatisfiableWriteConcern error',
'commitTransaction fails after Interrupted'
);
}
const testSuites = loadSpecTests(path.join('transactions', 'legacy'));
after(() => testContext.teardown());
before(function () {
return testContext.setup(this.configuration);
});
function testFilter(spec, configuration) {
return (
SKIP_TESTS.indexOf(spec.description) === -1 &&
(!gte(configuration.version, '7.1.0') || LATEST_SKIP_TESTS.indexOf(spec.description) === -1)
);
}
generateTopologyTests(testSuites, testContext, testFilter);
});