| 1 |
runOn: |
| 2 |
- |
| 3 |
minServerVersion: "4.0" |
| 4 |
topology: ["replicaset"] |
| 5 |
- |
| 6 |
minServerVersion: "4.1.8" |
| 7 |
topology: ["sharded"] |
| 8 |
|
| 9 |
database_name: &database_name "withTransaction-tests" |
| 10 |
collection_name: &collection_name "test" |
| 11 |
|
| 12 |
data: [] |
| 13 |
|
| 14 |
tests: |
| 15 |
- |
| 16 |
description: withTransaction commits after callback returns |
| 17 |
useMultipleMongoses: true |
| 18 |
operations: |
| 19 |
- |
| 20 |
name: withTransaction |
| 21 |
object: session0 |
| 22 |
arguments: |
| 23 |
callback: |
| 24 |
operations: |
| 25 |
- |
| 26 |
name: insertOne |
| 27 |
object: collection |
| 28 |
arguments: |
| 29 |
session: session0 |
| 30 |
document: { _id: 1 } |
| 31 |
result: |
| 32 |
insertedId: 1 |
| 33 |
- |
| 34 |
name: insertOne |
| 35 |
object: collection |
| 36 |
arguments: |
| 37 |
session: session0 |
| 38 |
document: { _id: 2 } |
| 39 |
result: |
| 40 |
insertedId: 2 |
| 41 |
expectations: |
| 42 |
- |
| 43 |
command_started_event: |
| 44 |
command: |
| 45 |
insert: *collection_name |
| 46 |
documents: |
| 47 |
- { _id: 1 } |
| 48 |
ordered: true |
| 49 |
lsid: session0 |
| 50 |
txnNumber: { $numberLong: "1" } |
| 51 |
startTransaction: true |
| 52 |
autocommit: false |
| 53 |
# omitted fields |
| 54 |
readConcern: ~ |
| 55 |
writeConcern: ~ |
| 56 |
command_name: insert |
| 57 |
database_name: *database_name |
| 58 |
- |
| 59 |
command_started_event: |
| 60 |
command: |
| 61 |
insert: *collection_name |
| 62 |
documents: |
| 63 |
- { _id: 2 } |
| 64 |
ordered: true |
| 65 |
lsid: session0 |
| 66 |
txnNumber: { $numberLong: "1" } |
| 67 |
autocommit: false |
| 68 |
# omitted fields |
| 69 |
readConcern: ~ |
| 70 |
startTransaction: ~ |
| 71 |
writeConcern: ~ |
| 72 |
command_name: insert |
| 73 |
database_name: *database_name |
| 74 |
- |
| 75 |
command_started_event: |
| 76 |
command: |
| 77 |
commitTransaction: 1 |
| 78 |
lsid: session0 |
| 79 |
txnNumber: { $numberLong: "1" } |
| 80 |
autocommit: false |
| 81 |
# omitted fields |
| 82 |
readConcern: ~ |
| 83 |
startTransaction: ~ |
| 84 |
writeConcern: ~ |
| 85 |
command_name: commitTransaction |
| 86 |
database_name: admin |
| 87 |
outcome: |
| 88 |
collection: |
| 89 |
data: |
| 90 |
- { _id: 1 } |
| 91 |
- { _id: 2 } |
| 92 |
- |
| 93 |
# In this scenario, the callback commits the transaction originally started |
| 94 |
# by withTransaction and starts a second transaction before returning. Since |
| 95 |
# withTransaction only examines the session's state, it should commit that |
| 96 |
# second transaction after the callback returns. |
| 97 |
description: withTransaction commits after callback returns (second transaction) |
| 98 |
useMultipleMongoses: true |
| 99 |
operations: |
| 100 |
- |
| 101 |
name: withTransaction |
| 102 |
object: session0 |
| 103 |
arguments: |
| 104 |
callback: |
| 105 |
operations: |
| 106 |
- |
| 107 |
name: insertOne |
| 108 |
object: collection |
| 109 |
arguments: |
| 110 |
session: session0 |
| 111 |
document: { _id: 1 } |
| 112 |
result: |
| 113 |
insertedId: 1 |
| 114 |
- |
| 115 |
name: commitTransaction |
| 116 |
object: session0 |
| 117 |
- |
| 118 |
name: startTransaction |
| 119 |
object: session0 |
| 120 |
- |
| 121 |
name: insertOne |
| 122 |
object: collection |
| 123 |
arguments: |
| 124 |
session: session0 |
| 125 |
document: { _id: 2 } |
| 126 |
result: |
| 127 |
insertedId: 2 |
| 128 |
expectations: |
| 129 |
- |
| 130 |
command_started_event: |
| 131 |
command: |
| 132 |
insert: *collection_name |
| 133 |
documents: |
| 134 |
- { _id: 1 } |
| 135 |
ordered: true |
| 136 |
lsid: session0 |
| 137 |
txnNumber: { $numberLong: "1" } |
| 138 |
startTransaction: true |
| 139 |
autocommit: false |
| 140 |
# omitted fields |
| 141 |
readConcern: ~ |
| 142 |
writeConcern: ~ |
| 143 |
command_name: insert |
| 144 |
database_name: *database_name |
| 145 |
- |
| 146 |
command_started_event: |
| 147 |
command: |
| 148 |
commitTransaction: 1 |
| 149 |
lsid: session0 |
| 150 |
txnNumber: { $numberLong: "1" } |
| 151 |
autocommit: false |
| 152 |
# omitted fields |
| 153 |
readConcern: ~ |
| 154 |
startTransaction: ~ |
| 155 |
writeConcern: ~ |
| 156 |
command_name: commitTransaction |
| 157 |
database_name: admin |
| 158 |
- |
| 159 |
command_started_event: |
| 160 |
command: |
| 161 |
insert: *collection_name |
| 162 |
documents: |
| 163 |
- { _id: 2 } |
| 164 |
ordered: true |
| 165 |
lsid: session0 |
| 166 |
# second transaction will be causally consistent with the first |
| 167 |
readConcern: { afterClusterTime: 42 } |
| 168 |
# txnNumber is incremented for the second transaction |
| 169 |
txnNumber: { $numberLong: "2" } |
| 170 |
startTransaction: true |
| 171 |
autocommit: false |
| 172 |
# omitted fields |
| 173 |
writeConcern: ~ |
| 174 |
command_name: insert |
| 175 |
database_name: *database_name |
| 176 |
- |
| 177 |
command_started_event: |
| 178 |
command: |
| 179 |
commitTransaction: 1 |
| 180 |
lsid: session0 |
| 181 |
txnNumber: { $numberLong: "2" } |
| 182 |
autocommit: false |
| 183 |
# omitted fields |
| 184 |
readConcern: ~ |
| 185 |
startTransaction: ~ |
| 186 |
writeConcern: ~ |
| 187 |
command_name: commitTransaction |
| 188 |
database_name: admin |
| 189 |
outcome: |
| 190 |
collection: |
| 191 |
data: |
| 192 |
- { _id: 1 } |
| 193 |
- { _id: 2 } |