Skip to content

Commit 6b1c149

Browse files
authored
RUBY-3063 sync transactions spec tests (#2569)
1 parent bb2e434 commit 6b1c149

File tree

3 files changed

+300
-0
lines changed

3 files changed

+300
-0
lines changed
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
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
description: "retryable abortTransaction on handshake errors"
2+
3+
schemaVersion: "1.4"
4+
5+
runOnRequirements:
6+
- minServerVersion: "4.2"
7+
topologies: [replicaset, sharded, load-balanced]
8+
serverless: "forbid"
9+
auth: true
10+
11+
createEntities:
12+
- client:
13+
id: &client0 client0
14+
useMultipleMongoses: false
15+
observeEvents: [commandStartedEvent, connectionCheckOutStartedEvent]
16+
- database:
17+
id: &database0 database0
18+
client: *client0
19+
databaseName: &databaseName retryable-handshake-tests
20+
- collection:
21+
id: &collection0 collection0
22+
database: *database0
23+
collectionName: &collectionName coll
24+
- session:
25+
# This session will be used to execute the transaction
26+
id: &session0 session0
27+
client: *client0
28+
- session:
29+
# This session will be used to create the failPoint, and empty the pool
30+
id: &session1 session1
31+
client: *client0
32+
33+
initialData:
34+
- collectionName: *collectionName
35+
databaseName: *databaseName
36+
documents:
37+
- { _id: 1, x: 11 }
38+
39+
tests:
40+
- description: "AbortTransaction succeeds after handshake network error"
41+
skipReason: "DRIVERS-2032: Pinned servers need to be checked if they are still selectable"
42+
operations:
43+
44+
- name: startTransaction
45+
object: *session0
46+
47+
- name: insertOne
48+
object: *collection0
49+
arguments:
50+
session: *session0
51+
document: { _id: 2, x: 22 }
52+
53+
# The following failPoint and ping utilize session1 so that
54+
# the transaction won't be failed by the intentional erroring of ping
55+
# and it will have an empty pool when it goes to run abortTransaction
56+
- name: failPoint # fail the next connection establishment
57+
object: testRunner
58+
arguments:
59+
client: *client0
60+
session: *session1
61+
failPoint:
62+
configureFailPoint: failCommand
63+
mode: { times: 2 }
64+
data:
65+
# use saslContinue here to avoid SDAM errors
66+
# this failPoint itself will create a usable connection in the connection pool
67+
# so we run a ping (with closeConnection: true) in order to discard the connection
68+
# before testing that abortTransaction will fail a handshake but will get retried
69+
failCommands: [saslContinue, ping]
70+
closeConnection: true
71+
72+
- name: runCommand
73+
object: *database0
74+
arguments:
75+
commandName: ping
76+
command: { ping: 1 }
77+
session: *session1
78+
expectError:
79+
isError: true
80+
81+
- name: abortTransaction
82+
object: *session0
83+
84+
expectEvents:
85+
- client: *client0
86+
eventType: cmap
87+
events:
88+
- { connectionCheckOutStartedEvent: {} } # startTransaction
89+
- { connectionCheckOutStartedEvent: {} } # insertOne
90+
- { connectionCheckOutStartedEvent: {} } # failPoint
91+
- { connectionCheckOutStartedEvent: {} } # abortTransaction
92+
- { connectionCheckOutStartedEvent: {} } # abortTransaction retry
93+
- client: *client0
94+
events:
95+
- commandStartedEvent:
96+
command:
97+
insert: *collectionName
98+
documents: [{ _id: 2, x: 22 }]
99+
startTransaction: true
100+
commandName: insert
101+
databaseName: *databaseName
102+
- commandStartedEvent:
103+
command:
104+
ping: 1
105+
databaseName: *databaseName
106+
- commandStartedEvent:
107+
command:
108+
abortTransaction: 1
109+
lsid:
110+
$$sessionLsid: *session0
111+
commandName: abortTransaction
112+
databaseName: admin
113+
114+
outcome:
115+
- collectionName: *collectionName
116+
databaseName: *databaseName
117+
documents:
118+
- { _id: 1, x: 11 }
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
description: "retryable commitTransaction on handshake errors"
2+
3+
schemaVersion: "1.4"
4+
5+
runOnRequirements:
6+
- minServerVersion: "4.2"
7+
topologies: [replicaset, sharded, load-balanced]
8+
serverless: "forbid"
9+
auth: true
10+
11+
createEntities:
12+
- client:
13+
id: &client0 client0
14+
useMultipleMongoses: false
15+
observeEvents: [commandStartedEvent, connectionCheckOutStartedEvent]
16+
uriOptions: { retryWrites: false } # commitTransaction is retryable regardless of this option being set
17+
- database:
18+
id: &database0 database0
19+
client: *client0
20+
databaseName: &databaseName retryable-handshake-tests
21+
- collection:
22+
id: &collection0 collection0
23+
database: *database0
24+
collectionName: &collectionName coll
25+
- session:
26+
id: &session0 session0
27+
client: *client0
28+
- session:
29+
id: &session1 session1
30+
client: *client0
31+
32+
initialData:
33+
- collectionName: *collectionName
34+
databaseName: *databaseName
35+
documents:
36+
- { _id: 1, x: 11 }
37+
38+
tests:
39+
- description: "CommitTransaction succeeds after handshake network error"
40+
skipReason: "DRIVERS-2032: Pinned servers need to be checked if they are still selectable"
41+
operations:
42+
43+
- name: startTransaction
44+
object: *session0
45+
46+
- name: insertOne
47+
object: *collection0
48+
arguments:
49+
session: *session0
50+
document: { _id: 2, x: 22 }
51+
52+
# The following failPoint and ping utilize session1 so that
53+
# the transaction won't be failed by the intentional erroring of ping
54+
# and it will have an empty pool when it goes to run commitTransaction
55+
- name: failPoint # fail the next connection establishment
56+
object: testRunner
57+
arguments:
58+
client: *client0
59+
session: *session1
60+
failPoint:
61+
configureFailPoint: failCommand
62+
mode: { times: 2 }
63+
data:
64+
# use saslContinue here to avoid SDAM errors
65+
# this failPoint itself will create a usable connection in the connection pool
66+
# so we run a ping (that also fails) in order to discard the connection
67+
# before testing that commitTransaction gets retried
68+
failCommands: [saslContinue, ping]
69+
closeConnection: true
70+
71+
- name: runCommand
72+
object: *database0
73+
arguments:
74+
commandName: ping
75+
command: { ping: 1 }
76+
session: *session1
77+
expectError:
78+
isError: true
79+
80+
- name: commitTransaction
81+
object: *session0
82+
83+
expectEvents:
84+
- client: *client0
85+
eventType: cmap
86+
events:
87+
- { connectionCheckOutStartedEvent: {} } # startTransaction
88+
- { connectionCheckOutStartedEvent: {} } # insertOne
89+
- { connectionCheckOutStartedEvent: {} } # failPoint
90+
- { connectionCheckOutStartedEvent: {} } # commitTransaction
91+
- { connectionCheckOutStartedEvent: {} } # commitTransaction retry
92+
- client: *client0
93+
events:
94+
- commandStartedEvent:
95+
command:
96+
insert: *collectionName
97+
documents: [{ _id: 2, x: 22 }]
98+
startTransaction: true
99+
commandName: insert
100+
databaseName: *databaseName
101+
- commandStartedEvent:
102+
command:
103+
ping: 1
104+
databaseName: *databaseName
105+
- commandStartedEvent:
106+
command:
107+
commitTransaction: 1
108+
lsid:
109+
$$sessionLsid: *session0
110+
commandName: commitTransaction
111+
databaseName: admin
112+
113+
outcome:
114+
- collectionName: *collectionName
115+
databaseName: *databaseName
116+
documents:
117+
- { _id: 1, x: 11 }
118+
- { _id: 2, x: 22 } # The write was still applied

0 commit comments

Comments
 (0)