Skip to content

Commit 8694ef5

Browse files
RUST-1418 Add test that reads are not retried in a transaction (#720)
1 parent 3dcf919 commit 8694ef5

File tree

3 files changed

+208
-15
lines changed

3 files changed

+208
-15
lines changed

src/test/spec/json/transactions/README.rst

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,21 @@ Each YAML file has the following keys:
112112
and "sharded". If this field is omitted, the default is all topologies (i.e.
113113
``["single", "replicaset", "sharded"]``).
114114

115-
- ``serverless``: Optional string. Whether or not the test should be run on
116-
serverless instances imitating sharded clusters. Valid values are "require",
117-
"forbid", and "allow". If "require", the test MUST only be run on serverless
118-
instances. If "forbid", the test MUST NOT be run on serverless instances. If
119-
omitted or "allow", this option has no effect.
120-
121-
The test runner MUST be informed whether or not serverless is being used in
122-
order to determine if this requirement is met (e.g. through an environment
123-
variable or configuration option). Since the serverless proxy imitates a
124-
mongos, the runner is not capable of determining this by issuing a server
125-
command such as ``buildInfo`` or ``hello``.
115+
- ``serverless``: (optional): Whether or not the test should be run on Atlas
116+
Serverless instances. Valid values are "require", "forbid", and "allow". If
117+
"require", the test MUST only be run on Atlas Serverless instances. If
118+
"forbid", the test MUST NOT be run on Atlas Serverless instances. If omitted
119+
or "allow", this option has no effect.
120+
121+
The test runner MUST be informed whether or not Atlas Serverless is being
122+
used in order to determine if this requirement is met (e.g. through an
123+
environment variable or configuration option).
124+
125+
Note: the Atlas Serverless proxy imitates mongos, so the test runner is not
126+
capable of determining if Atlas Serverless is in use by issuing commands
127+
such as ``buildInfo`` or ``hello``. Furthermore, connections to Atlas
128+
Serverless use a load balancer, so the topology will appear as
129+
"load-balanced".
126130

127131
- ``database_name`` and ``collection_name``: The database and collection to use
128132
for testing.
@@ -138,10 +142,19 @@ Each YAML file has the following keys:
138142
- ``skipReason``: Optional, string describing why this test should be
139143
skipped.
140144

141-
- ``useMultipleMongoses`` (optional): If ``true``, the MongoClient for this
142-
test should be initialized with multiple mongos seed addresses. If ``false``
143-
or omitted, only a single mongos address should be specified. This field has
144-
no effect for non-sharded topologies.
145+
- ``useMultipleMongoses`` (optional): If ``true``, and the topology type is
146+
``Sharded``, the MongoClient for this test should be initialized with multiple
147+
mongos seed addresses. If ``false`` or omitted, only a single mongos address
148+
should be specified.
149+
150+
If ``true``, the topology type is ``LoadBalanced``, and Atlas Serverless is
151+
not being used, the MongoClient for this test should be initialized with the
152+
URI of the load balancer fronting multiple servers. If ``false`` or omitted,
153+
the MongoClient for this test should be initialized with the URI of the load
154+
balancer fronting a single server.
155+
156+
``useMultipleMongoses`` only affects ``Sharded`` and ``LoadBalanced``
157+
topologies (excluding Atlas Serverless).
145158

146159
- ``clientOptions``: Optional, parameters to pass to MongoClient().
147160

@@ -650,6 +663,7 @@ is the only command allowed in a sharded transaction that uses the
650663
Changelog
651664
=========
652665

666+
:2022-04-22: Clarifications to ``serverless`` and ``useMultipleMongoses``.
653667
:2019-05-15: Add operation level ``error`` field to assert any error.
654668
:2019-03-25: Add workaround for StaleDbVersion on distinct.
655669
:2019-03-01: Add top-level ``runOn`` field to denote server version and/or
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"description": "do not retry read in a transaction",
3+
"schemaVersion": "1.4",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "4.0.0",
7+
"topologies": [
8+
"replicaset"
9+
]
10+
},
11+
{
12+
"minServerVersion": "4.2.0",
13+
"topologies": [
14+
"sharded",
15+
"load-balanced"
16+
]
17+
}
18+
],
19+
"createEntities": [
20+
{
21+
"client": {
22+
"id": "client0",
23+
"useMultipleMongoses": false,
24+
"observeEvents": [
25+
"commandStartedEvent"
26+
],
27+
"uriOptions": {
28+
"retryReads": true
29+
}
30+
}
31+
},
32+
{
33+
"database": {
34+
"id": "database0",
35+
"client": "client0",
36+
"databaseName": "retryable-read-in-transaction-test"
37+
}
38+
},
39+
{
40+
"collection": {
41+
"id": "collection0",
42+
"database": "database0",
43+
"collectionName": "coll"
44+
}
45+
},
46+
{
47+
"session": {
48+
"id": "session0",
49+
"client": "client0"
50+
}
51+
}
52+
],
53+
"tests": [
54+
{
55+
"description": "find does not retry in a transaction",
56+
"operations": [
57+
{
58+
"name": "startTransaction",
59+
"object": "session0"
60+
},
61+
{
62+
"name": "failPoint",
63+
"object": "testRunner",
64+
"arguments": {
65+
"client": "client0",
66+
"failPoint": {
67+
"configureFailPoint": "failCommand",
68+
"mode": {
69+
"times": 1
70+
},
71+
"data": {
72+
"failCommands": [
73+
"find"
74+
],
75+
"closeConnection": true
76+
}
77+
}
78+
}
79+
},
80+
{
81+
"name": "find",
82+
"object": "collection0",
83+
"arguments": {
84+
"filter": {},
85+
"session": "session0"
86+
},
87+
"expectError": {
88+
"isError": true,
89+
"errorLabelsContain": [
90+
"TransientTransactionError"
91+
]
92+
}
93+
}
94+
],
95+
"expectEvents": [
96+
{
97+
"client": "client0",
98+
"events": [
99+
{
100+
"commandStartedEvent": {
101+
"command": {
102+
"find": "coll",
103+
"filter": {},
104+
"startTransaction": true
105+
},
106+
"commandName": "find",
107+
"databaseName": "retryable-read-in-transaction-test"
108+
}
109+
}
110+
]
111+
}
112+
]
113+
}
114+
]
115+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
description: "do not retry read in a transaction"
2+
3+
schemaVersion: "1.4"
4+
5+
runOnRequirements:
6+
- minServerVersion: "4.0.0"
7+
topologies: [ replicaset ]
8+
- minServerVersion: "4.2.0"
9+
topologies: [ sharded, load-balanced ]
10+
11+
createEntities:
12+
- client:
13+
id: &client0 client0
14+
useMultipleMongoses: false
15+
observeEvents: [commandStartedEvent]
16+
uriOptions: { retryReads: true }
17+
- database:
18+
id: &database0 database0
19+
client: *client0
20+
databaseName: &databaseName retryable-read-in-transaction-test
21+
- collection:
22+
id: &collection0 collection0
23+
database: *database0
24+
collectionName: &collectionName coll
25+
- session:
26+
id: &session0 session0
27+
client: *client0
28+
29+
tests:
30+
- description: "find does not retry in a transaction"
31+
operations:
32+
33+
- name: startTransaction
34+
object: *session0
35+
36+
- name: failPoint # fail the following find command
37+
object: testRunner
38+
arguments:
39+
client: *client0
40+
failPoint:
41+
configureFailPoint: failCommand
42+
mode: { times: 1 }
43+
data:
44+
failCommands: [find]
45+
closeConnection: true
46+
47+
- name: find
48+
object: *collection0
49+
arguments:
50+
filter: {}
51+
session: *session0
52+
expectError:
53+
isError: true
54+
errorLabelsContain: ["TransientTransactionError"]
55+
expectEvents:
56+
- client: *client0
57+
events:
58+
- commandStartedEvent:
59+
command:
60+
find: *collectionName
61+
filter: {}
62+
startTransaction: true
63+
commandName: find
64+
databaseName: *databaseName

0 commit comments

Comments
 (0)