mongo 2.7.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +39 -14
  5. data/Rakefile +1 -0
  6. data/lib/mongo/auth.rb +4 -1
  7. data/lib/mongo/client.rb +4 -3
  8. data/lib/mongo/cluster.rb +1 -1
  9. data/lib/mongo/collection/view/readable.rb +5 -2
  10. data/lib/mongo/database.rb +1 -0
  11. data/lib/mongo/error/invalid_server_preference.rb +1 -0
  12. data/lib/mongo/error/operation_failure.rb +10 -0
  13. data/lib/mongo/error/parser.rb +10 -0
  14. data/lib/mongo/event.rb +1 -2
  15. data/lib/mongo/operation/result.rb +4 -1
  16. data/lib/mongo/operation/shared/executable_transaction_label.rb +3 -1
  17. data/lib/mongo/operation/shared/sessions_supported.rb +1 -1
  18. data/lib/mongo/protocol/msg.rb +1 -1
  19. data/lib/mongo/protocol/query.rb +2 -2
  20. data/lib/mongo/retryable.rb +20 -6
  21. data/lib/mongo/server.rb +6 -0
  22. data/lib/mongo/server/connection.rb +4 -4
  23. data/lib/mongo/server/monitor/connection.rb +9 -5
  24. data/lib/mongo/server_selector/selectable.rb +86 -32
  25. data/lib/mongo/session.rb +98 -15
  26. data/lib/mongo/version.rb +1 -1
  27. data/spec/README.md +85 -0
  28. data/spec/integration/bulk_insert_spec.rb +1 -1
  29. data/spec/integration/change_stream_examples_spec.rb +3 -1
  30. data/spec/integration/change_stream_spec.rb +10 -14
  31. data/spec/integration/client_construction_spec.rb +1 -0
  32. data/spec/integration/command_monitoring_spec.rb +37 -1
  33. data/spec/integration/command_spec.rb +141 -0
  34. data/spec/integration/connection_spec.rb +4 -2
  35. data/spec/integration/cursor_reaping_spec.rb +1 -1
  36. data/spec/integration/docs_examples_spec.rb +1 -1
  37. data/spec/integration/retryable_writes_spec.rb +33 -42
  38. data/spec/integration/server_description_spec.rb +3 -3
  39. data/spec/integration/server_selector_spec.rb +79 -0
  40. data/spec/lite_spec_helper.rb +4 -2
  41. data/spec/mongo/address_spec.rb +8 -0
  42. data/spec/mongo/auth/cr_spec.rb +5 -2
  43. data/spec/mongo/auth/invalid_mechanism_spec.rb +11 -0
  44. data/spec/mongo/auth/scram/conversation_spec.rb +3 -2
  45. data/spec/mongo/auth/scram/negotiation_spec.rb +1 -2
  46. data/spec/mongo/auth/scram_spec.rb +11 -6
  47. data/spec/mongo/auth/user/view_spec.rb +13 -6
  48. data/spec/mongo/bulk_write_spec.rb +81 -104
  49. data/spec/mongo/client_construction_spec.rb +18 -7
  50. data/spec/mongo/client_spec.rb +11 -7
  51. data/spec/mongo/cluster_spec.rb +30 -1
  52. data/spec/mongo/collection/view/aggregation_spec.rb +18 -10
  53. data/spec/mongo/collection/view/change_stream_spec.rb +28 -8
  54. data/spec/mongo/collection/view/map_reduce_spec.rb +24 -10
  55. data/spec/mongo/collection/view/readable_spec.rb +37 -19
  56. data/spec/mongo/collection/view/writable_spec.rb +64 -32
  57. data/spec/mongo/collection/view_spec.rb +4 -2
  58. data/spec/mongo/collection_spec.rb +163 -73
  59. data/spec/mongo/cursor_spec.rb +5 -2
  60. data/spec/mongo/database_spec.rb +41 -19
  61. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  62. data/spec/mongo/error/parser_spec.rb +29 -0
  63. data/spec/mongo/grid/stream/write_spec.rb +2 -1
  64. data/spec/mongo/index/view_spec.rb +42 -24
  65. data/spec/mongo/operation/delete/op_msg_spec.rb +11 -7
  66. data/spec/mongo/operation/insert/op_msg_spec.rb +10 -6
  67. data/spec/mongo/operation/update/op_msg_spec.rb +10 -6
  68. data/spec/mongo/protocol/compressed_spec.rb +1 -1
  69. data/spec/mongo/protocol/msg_spec.rb +1 -1
  70. data/spec/mongo/server/app_metadata_spec.rb +2 -1
  71. data/spec/mongo/server/connection_auth_spec.rb +1 -1
  72. data/spec/mongo/server/monitor/connection_spec.rb +42 -0
  73. data/spec/mongo/server_selector_spec.rb +17 -0
  74. data/spec/mongo/server_spec.rb +110 -0
  75. data/spec/mongo/session/session_pool_spec.rb +1 -1
  76. data/spec/mongo/session_spec.rb +1 -1
  77. data/spec/mongo/session_transaction_spec.rb +162 -1
  78. data/spec/mongo/socket/ssl_spec.rb +14 -7
  79. data/spec/mongo/uri/srv_protocol_spec.rb +41 -34
  80. data/spec/spec_helper.rb +3 -191
  81. data/spec/spec_tests/change_streams_spec.rb +3 -6
  82. data/spec/spec_tests/data/transactions/abort.yml +3 -1
  83. data/spec/spec_tests/data/transactions/commit.yml +4 -3
  84. data/spec/spec_tests/data/transactions/error-labels.yml +17 -13
  85. data/spec/spec_tests/data/transactions/read-concern.yml +611 -0
  86. data/spec/spec_tests/data/transactions/retryable-commit.yml +126 -21
  87. data/spec/spec_tests/data/transactions_api/callback-aborts.yml +42 -39
  88. data/spec/spec_tests/data/transactions_api/callback-commits.yml +52 -50
  89. data/spec/spec_tests/data/transactions_api/callback-retry.yml +33 -31
  90. data/spec/spec_tests/data/transactions_api/commit-retry.yml +42 -39
  91. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +13 -12
  92. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +15 -26
  93. data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +25 -33
  94. data/spec/spec_tests/data/transactions_api/commit.yml +44 -42
  95. data/spec/spec_tests/data/transactions_api/transaction-options.yml +25 -23
  96. data/spec/spec_tests/max_staleness_spec.rb +2 -0
  97. data/spec/spec_tests/retryable_writes_spec.rb +2 -6
  98. data/spec/spec_tests/sdam_spec.rb +2 -0
  99. data/spec/spec_tests/server_selection_spec.rb +3 -0
  100. data/spec/spec_tests/transactions_api_spec.rb +7 -1
  101. data/spec/spec_tests/transactions_spec.rb +6 -0
  102. data/spec/spec_tests/uri_options_spec.rb +4 -26
  103. data/spec/support/certificates/ca.pem +21 -16
  104. data/spec/support/certificates/client.pem +90 -90
  105. data/spec/support/certificates/client_cert.pem +21 -20
  106. data/spec/support/certificates/client_key.pem +27 -28
  107. data/spec/support/certificates/client_key_encrypted.pem +26 -26
  108. data/spec/support/certificates/crl.pem +10 -8
  109. data/spec/support/certificates/crl_client_revoked.pem +11 -10
  110. data/spec/support/certificates/server.pem +48 -33
  111. data/spec/support/change_streams.rb +12 -32
  112. data/spec/support/client_registry.rb +12 -1
  113. data/spec/support/cluster_config.rb +48 -2
  114. data/spec/support/common_shortcuts.rb +73 -7
  115. data/spec/support/connection_string.rb +0 -3
  116. data/spec/support/constraints.rb +87 -22
  117. data/spec/support/crud.rb +2 -1
  118. data/spec/support/shared/server_selector.rb +0 -28
  119. data/spec/support/shared/session.rb +25 -14
  120. data/spec/support/transactions.rb +4 -8
  121. data/spec/support/transactions/operation.rb +26 -4
  122. data/spec/support/transactions/verifier.rb +5 -2
  123. metadata +496 -488
  124. metadata.gz.sig +5 -2
  125. data/spec/support/certificates/password_protected.pem +0 -51
@@ -16,18 +16,19 @@ tests:
16
16
  -
17
17
  name: withTransaction
18
18
  object: session0
19
- callback:
20
- operations:
21
- -
22
- # We do not assert the result here, as insertOne will fail for the
23
- # first two executions of the callback before ultimately
24
- # succeeding and returning a result. Asserting the state of the
25
- # output collection after the test is sufficient.
26
- name: insertOne
27
- object: collection
28
- arguments:
29
- session: session0
30
- document: { _id: 1 }
19
+ arguments:
20
+ callback:
21
+ operations:
22
+ -
23
+ # We do not assert the result here, as insertOne will fail for
24
+ # the first two executions of the callback before ultimately
25
+ # succeeding and returning a result. Asserting the state of the
26
+ # output collection after the test is sufficient.
27
+ name: insertOne
28
+ object: collection
29
+ arguments:
30
+ session: session0
31
+ document: { _id: 1 }
31
32
  expectations:
32
33
  -
33
34
  command_started_event:
@@ -130,25 +131,26 @@ tests:
130
131
  -
131
132
  name: withTransaction
132
133
  object: session0
133
- callback:
134
- operations:
135
- -
136
- name: insertOne
137
- object: collection
138
- arguments:
139
- session: session0
140
- document: { _id: 1 }
141
- result:
142
- insertedId: 1
143
- -
144
- name: insertOne
145
- object: collection
146
- arguments:
147
- session: session0
148
- document: { _id: 1 }
149
- result:
150
- errorCodeName: DuplicateKey
151
- errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
134
+ arguments:
135
+ callback:
136
+ operations:
137
+ -
138
+ name: insertOne
139
+ object: collection
140
+ arguments:
141
+ session: session0
142
+ document: { _id: 1 }
143
+ result:
144
+ insertedId: 1
145
+ -
146
+ name: insertOne
147
+ object: collection
148
+ arguments:
149
+ session: session0
150
+ document: { _id: 1 }
151
+ result:
152
+ errorCodeName: DuplicateKey
153
+ errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
152
154
  result:
153
155
  errorCodeName: DuplicateKey
154
156
  errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
@@ -6,7 +6,6 @@ data: []
6
6
  tests:
7
7
  -
8
8
  description: commitTransaction succeeds after multiple connection errors
9
- skipReason: SPEC-1185 Drivers should use majority write concern when retrying commitTransaction
10
9
  failPoint:
11
10
  configureFailPoint: failCommand
12
11
  mode: { times: 2 }
@@ -17,16 +16,17 @@ tests:
17
16
  -
18
17
  name: withTransaction
19
18
  object: session0
20
- callback:
21
- operations:
22
- -
23
- name: insertOne
24
- object: collection
25
- arguments:
26
- session: session0
27
- document: { _id: 1 }
28
- result:
29
- insertedId: 1
19
+ arguments:
20
+ callback:
21
+ operations:
22
+ -
23
+ name: insertOne
24
+ object: collection
25
+ arguments:
26
+ session: session0
27
+ document: { _id: 1 }
28
+ result:
29
+ insertedId: 1
30
30
  expectations:
31
31
  -
32
32
  command_started_event:
@@ -65,7 +65,7 @@ tests:
65
65
  txnNumber: { $numberLong: "1" }
66
66
  autocommit: false
67
67
  # commitTransaction applies w:majority on retries (SPEC-1185)
68
- writeConcern: { w: majority }
68
+ writeConcern: { w: majority, wtimeout: 10000 }
69
69
  # omitted fields
70
70
  readConcern: ~
71
71
  startTransaction: ~
@@ -79,7 +79,7 @@ tests:
79
79
  txnNumber: { $numberLong: "1" }
80
80
  autocommit: false
81
81
  # commitTransaction applies w:majority on retries (SPEC-1185)
82
- writeConcern: { w: majority }
82
+ writeConcern: { w: majority, wtimeout: 10000 }
83
83
  # omitted fields
84
84
  readConcern: ~
85
85
  startTransaction: ~
@@ -91,7 +91,6 @@ tests:
91
91
  - { _id: 1 }
92
92
  -
93
93
  description: commitTransaction retry only overwrites write concern w option
94
- skipReason: SPEC-1185 Drivers should use majority write concern when retrying commitTransaction
95
94
  failPoint:
96
95
  configureFailPoint: failCommand
97
96
  mode: { times: 2 }
@@ -102,18 +101,19 @@ tests:
102
101
  -
103
102
  name: withTransaction
104
103
  object: session0
105
- callback:
106
- operations:
107
- -
108
- name: insertOne
109
- object: collection
110
- arguments:
111
- session: session0
112
- document: { _id: 1 }
113
- result:
114
- insertedId: 1
115
- transactionOptions:
116
- writeConcern: { w: 2, j: true, wtimeout: 5000 }
104
+ arguments:
105
+ callback:
106
+ operations:
107
+ -
108
+ name: insertOne
109
+ object: collection
110
+ arguments:
111
+ session: session0
112
+ document: { _id: 1 }
113
+ result:
114
+ insertedId: 1
115
+ options:
116
+ writeConcern: { w: 2, j: true, wtimeout: 5000 }
117
117
  expectations:
118
118
  -
119
119
  command_started_event:
@@ -189,16 +189,17 @@ tests:
189
189
  -
190
190
  name: withTransaction
191
191
  object: session0
192
- callback:
193
- operations:
194
- -
195
- name: insertOne
196
- object: collection
197
- arguments:
198
- session: session0
199
- document: { _id: 1 }
200
- result:
201
- insertedId: 1
192
+ arguments:
193
+ callback:
194
+ operations:
195
+ -
196
+ name: insertOne
197
+ object: collection
198
+ arguments:
199
+ session: session0
200
+ document: { _id: 1 }
201
+ result:
202
+ insertedId: 1
202
203
  expectations:
203
204
  -
204
205
  command_started_event:
@@ -236,10 +237,11 @@ tests:
236
237
  lsid: session0
237
238
  txnNumber: { $numberLong: "1" }
238
239
  autocommit: false
240
+ # commitTransaction applies w:majority on retries (SPEC-1185)
241
+ writeConcern: { w: majority, wtimeout: 10000 }
239
242
  # omitted fields
240
243
  readConcern: ~
241
244
  startTransaction: ~
242
- writeConcern: ~
243
245
  command_name: commitTransaction
244
246
  database_name: admin
245
247
  -
@@ -249,13 +251,14 @@ tests:
249
251
  lsid: session0
250
252
  txnNumber: { $numberLong: "1" }
251
253
  autocommit: false
254
+ # commitTransaction applies w:majority on retries (SPEC-1185)
255
+ writeConcern: { w: majority, wtimeout: 10000 }
252
256
  # omitted fields
253
257
  readConcern: ~
254
258
  startTransaction: ~
255
- writeConcern: ~
256
259
  command_name: commitTransaction
257
260
  database_name: admin
258
- outcome: &outcome
261
+ outcome:
259
262
  collection:
260
263
  data:
261
264
  - { _id: 1 }
@@ -24,17 +24,18 @@ tests:
24
24
  -
25
25
  name: withTransaction
26
26
  object: session0
27
- callback: &callback
28
- operations:
29
- -
30
- name: insertOne
31
- object: collection
32
- arguments:
33
- session: session0
34
- document: { _id: 1 }
35
- result:
36
- insertedId: 1
37
- expectations: &expectations
27
+ arguments:
28
+ callback:
29
+ operations:
30
+ -
31
+ name: insertOne
32
+ object: collection
33
+ arguments:
34
+ session: session0
35
+ document: { _id: 1 }
36
+ result:
37
+ insertedId: 1
38
+ expectations:
38
39
  -
39
40
  command_started_event:
40
41
  command:
@@ -126,7 +127,7 @@ tests:
126
127
  writeConcern: ~
127
128
  command_name: commitTransaction
128
129
  database_name: admin
129
- outcome: &outcome
130
+ outcome:
130
131
  collection:
131
132
  data:
132
133
  - { _id: 1 }
@@ -18,20 +18,21 @@ tests:
18
18
  failCommands: ["commitTransaction"]
19
19
  errorCode: 24 # LockTimeout
20
20
  closeConnection: false
21
- operations:
21
+ operations: &operations
22
22
  -
23
23
  name: withTransaction
24
24
  object: session0
25
- callback: &callback
26
- operations:
27
- -
28
- name: insertOne
29
- object: collection
30
- arguments:
31
- session: session0
32
- document: { _id: 1 }
33
- result:
34
- insertedId: 1
25
+ arguments:
26
+ callback:
27
+ operations:
28
+ -
29
+ name: insertOne
30
+ object: collection
31
+ arguments:
32
+ session: session0
33
+ document: { _id: 1 }
34
+ result:
35
+ insertedId: 1
35
36
  expectations: &expectations
36
37
  -
37
38
  command_started_event:
@@ -137,11 +138,7 @@ tests:
137
138
  failCommands: ["commitTransaction"]
138
139
  errorCode: 112 # WriteConflict
139
140
  closeConnection: false
140
- operations:
141
- -
142
- name: withTransaction
143
- object: session0
144
- callback: *callback
141
+ operations: *operations
145
142
  expectations: *expectations
146
143
  outcome: *outcome
147
144
  -
@@ -153,11 +150,7 @@ tests:
153
150
  failCommands: ["commitTransaction"]
154
151
  errorCode: 246 # SnapshotUnavailable
155
152
  closeConnection: false
156
- operations:
157
- -
158
- name: withTransaction
159
- object: session0
160
- callback: *callback
153
+ operations: *operations
161
154
  expectations: *expectations
162
155
  outcome: *outcome
163
156
  -
@@ -169,10 +162,6 @@ tests:
169
162
  failCommands: ["commitTransaction"]
170
163
  errorCode: 251 # NoSuchTransaction
171
164
  closeConnection: false
172
- operations:
173
- -
174
- name: withTransaction
175
- object: session0
176
- callback: *callback
165
+ operations: *operations
177
166
  expectations: *expectations
178
167
  outcome: *outcome
@@ -6,14 +6,13 @@ data: []
6
6
  tests:
7
7
  -
8
8
  description: commitTransaction is not retried after WriteConcernFailed timeout error
9
- skipReason: SPEC-1197 Drivers should not retry commit after wtimeout error
10
9
  failPoint:
11
10
  configureFailPoint: failCommand
12
11
  mode: { times: 1 }
13
12
  data:
14
13
  failCommands: ["commitTransaction"]
15
14
  # Do not specify closeConnection: false, since that would conflict
16
- # with writeConcernError (likely a server bug)
15
+ # with writeConcernError (see: SERVER-39292)
17
16
  writeConcernError:
18
17
  code: 64
19
18
  codeName: WriteConcernFailed
@@ -23,20 +22,22 @@ tests:
23
22
  -
24
23
  name: withTransaction
25
24
  object: session0
26
- callback: &callback
27
- operations:
28
- -
29
- name: insertOne
30
- object: collection
31
- arguments:
32
- session: session0
33
- document: { _id: 1 }
34
- result:
35
- insertedId: 1
25
+ arguments: &arguments
26
+ callback:
27
+ operations:
28
+ -
29
+ name: insertOne
30
+ object: collection
31
+ arguments:
32
+ session: session0
33
+ document: { _id: 1 }
34
+ result:
35
+ insertedId: 1
36
36
  result:
37
37
  errorCodeName: WriteConcernFailed
38
38
  # Per transactions spec, drivers add UnknownTransactionCommitResult
39
- # label for WriteConcernFailed errors
39
+ # label for WriteConcernFailed errors; however, neither the driver
40
+ # nor withTransaction() will retry the commit in this case.
40
41
  errorLabelsContain: ["UnknownTransactionCommitResult"]
41
42
  errorLabelsOmit: ["TransientTransactionError"]
42
43
  expectations:
@@ -75,36 +76,27 @@ tests:
75
76
  data:
76
77
  - { _id: 1 }
77
78
  -
78
- # This test configures the fail point to return a contrived error that
79
- # is WriteConcernFailed but omits the errInfo field that would identify it
80
- # as a wtimeout error. This tests that drivers do not assume that all
79
+ # This test configures the fail point to return an error with the
80
+ # WriteConcernFailed code but without errInfo that would identify it as a
81
+ # wtimeout error. This tests that drivers do not assume that all
81
82
  # WriteConcernFailed errors are due to a replication timeout.
82
83
  description: commitTransaction is retried after WriteConcernFailed non-timeout error
83
- skipReason: SPEC-1185 Drivers should use majority write concern when retrying commitTransaction
84
84
  failPoint:
85
85
  configureFailPoint: failCommand
86
86
  mode: { times: 2 }
87
87
  data:
88
88
  failCommands: ["commitTransaction"]
89
- closeConnection: false
89
+ # Do not specify closeConnection: false, since that would conflict
90
+ # with writeConcernError (see: SERVER-39292)
90
91
  writeConcernError:
91
92
  code: 64
92
93
  codeName: WriteConcernFailed
93
- errmsg: "waiting for replication did not time out"
94
+ errmsg: "multiple errors reported"
94
95
  operations:
95
96
  -
96
97
  name: withTransaction
97
98
  object: session0
98
- callback:
99
- operations:
100
- -
101
- name: insertOne
102
- object: collection
103
- arguments:
104
- session: session0
105
- document: { _id: 1 }
106
- result:
107
- insertedId: 1
99
+ arguments: *arguments
108
100
  expectations:
109
101
  -
110
102
  command_started_event:
@@ -143,7 +135,7 @@ tests:
143
135
  txnNumber: { $numberLong: "1" }
144
136
  autocommit: false
145
137
  # commitTransaction applies w:majority on retries (SPEC-1185)
146
- writeConcern: { w: majority }
138
+ writeConcern: { w: majority, wtimeout: 10000 }
147
139
  # omitted fields
148
140
  readConcern: ~
149
141
  startTransaction: ~
@@ -157,7 +149,7 @@ tests:
157
149
  txnNumber: { $numberLong: "1" }
158
150
  autocommit: false
159
151
  # commitTransaction applies w:majority on retries (SPEC-1185)
160
- writeConcern: { w: majority }
152
+ writeConcern: { w: majority, wtimeout: 10000 }
161
153
  # omitted fields
162
154
  readConcern: ~
163
155
  startTransaction: ~
@@ -182,7 +174,7 @@ tests:
182
174
  -
183
175
  name: withTransaction
184
176
  object: session0
185
- callback: *callback
177
+ arguments: *arguments
186
178
  result:
187
179
  errorCodeName: UnknownReplWriteConcern
188
180
  errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
@@ -232,7 +224,7 @@ tests:
232
224
  -
233
225
  name: withTransaction
234
226
  object: session0
235
- callback: *callback
227
+ arguments: *arguments
236
228
  result:
237
229
  errorCodeName: UnsatisfiableWriteConcern
238
230
  errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]