mongo 2.9.2 → 2.10.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongo.rb +1 -0
  5. data/lib/mongo/auth/user/view.rb +4 -4
  6. data/lib/mongo/bulk_write.rb +14 -8
  7. data/lib/mongo/bulk_write/result.rb +1 -1
  8. data/lib/mongo/bulk_write/result_combiner.rb +2 -2
  9. data/lib/mongo/bulk_write/transformable.rb +17 -9
  10. data/lib/mongo/client.rb +107 -16
  11. data/lib/mongo/cluster.rb +47 -25
  12. data/lib/mongo/cluster/topology/replica_set_no_primary.rb +1 -1
  13. data/lib/mongo/cluster_time.rb +139 -0
  14. data/lib/mongo/collection.rb +84 -25
  15. data/lib/mongo/collection/view.rb +7 -3
  16. data/lib/mongo/collection/view/aggregation.rb +4 -4
  17. data/lib/mongo/collection/view/builder/aggregation.rb +31 -6
  18. data/lib/mongo/collection/view/builder/find_command.rb +4 -1
  19. data/lib/mongo/collection/view/builder/map_reduce.rb +4 -1
  20. data/lib/mongo/collection/view/change_stream.rb +54 -66
  21. data/lib/mongo/collection/view/iterable.rb +2 -2
  22. data/lib/mongo/collection/view/map_reduce.rb +6 -4
  23. data/lib/mongo/collection/view/readable.rb +36 -16
  24. data/lib/mongo/collection/view/writable.rb +68 -22
  25. data/lib/mongo/cursor.rb +87 -20
  26. data/lib/mongo/database.rb +47 -43
  27. data/lib/mongo/database/view.rb +54 -11
  28. data/lib/mongo/error.rb +13 -4
  29. data/lib/mongo/error/invalid_write_concern.rb +2 -2
  30. data/lib/mongo/error/operation_failure.rb +65 -11
  31. data/lib/mongo/error/parser.rb +41 -8
  32. data/lib/mongo/grid/fs_bucket.rb +26 -6
  33. data/lib/mongo/grid/stream/read.rb +9 -2
  34. data/lib/mongo/grid/stream/write.rb +21 -5
  35. data/lib/mongo/index/view.rb +3 -3
  36. data/lib/mongo/lint.rb +10 -3
  37. data/lib/mongo/operation.rb +2 -0
  38. data/lib/mongo/operation/aggregate/result.rb +19 -6
  39. data/lib/mongo/operation/collections_info.rb +1 -1
  40. data/lib/mongo/operation/get_more/result.rb +9 -0
  41. data/lib/mongo/operation/list_collections/command.rb +1 -3
  42. data/lib/mongo/operation/list_collections/op_msg.rb +1 -2
  43. data/lib/mongo/operation/parallel_scan/command.rb +4 -1
  44. data/lib/mongo/operation/parallel_scan/op_msg.rb +4 -1
  45. data/lib/mongo/operation/result.rb +27 -4
  46. data/lib/mongo/operation/shared/executable.rb +19 -5
  47. data/lib/mongo/operation/shared/executable_no_validate.rb +1 -2
  48. data/lib/mongo/operation/shared/executable_transaction_label.rb +0 -9
  49. data/lib/mongo/operation/shared/polymorphic_result.rb +9 -1
  50. data/lib/mongo/operation/shared/result/aggregatable.rb +2 -2
  51. data/lib/mongo/operation/shared/sessions_supported.rb +42 -32
  52. data/lib/mongo/operation/shared/specifiable.rb +40 -0
  53. data/lib/mongo/operation/shared/unpinnable.rb +39 -0
  54. data/lib/mongo/operation/shared/write.rb +1 -1
  55. data/lib/mongo/protocol/update.rb +6 -2
  56. data/lib/mongo/retryable.rb +79 -39
  57. data/lib/mongo/server/connection.rb +10 -3
  58. data/lib/mongo/server/description.rb +25 -1
  59. data/lib/mongo/server/monitor/connection.rb +1 -1
  60. data/lib/mongo/server_selector.rb +10 -0
  61. data/lib/mongo/server_selector/selectable.rb +172 -32
  62. data/lib/mongo/session.rb +654 -581
  63. data/lib/mongo/session/session_pool.rb +1 -1
  64. data/lib/mongo/socket.rb +7 -28
  65. data/lib/mongo/socket/ssl.rb +26 -1
  66. data/lib/mongo/socket/tcp.rb +3 -0
  67. data/lib/mongo/socket/unix.rb +3 -0
  68. data/lib/mongo/uri.rb +112 -265
  69. data/lib/mongo/uri/srv_protocol.rb +4 -1
  70. data/lib/mongo/version.rb +1 -1
  71. data/lib/mongo/write_concern.rb +10 -29
  72. data/lib/mongo/write_concern/acknowledged.rb +12 -0
  73. data/lib/mongo/write_concern/base.rb +17 -13
  74. data/lib/mongo/write_concern/unacknowledged.rb +12 -0
  75. data/spec/atlas/atlas_connectivity_spec.rb +7 -37
  76. data/spec/atlas/operations_spec.rb +25 -0
  77. data/spec/integration/change_stream_examples_spec.rb +45 -31
  78. data/spec/integration/change_stream_spec.rb +305 -5
  79. data/spec/integration/client_spec.rb +44 -0
  80. data/spec/integration/command_monitoring_spec.rb +1 -0
  81. data/spec/integration/command_spec.rb +7 -1
  82. data/spec/integration/mmapv1_spec.rb +28 -0
  83. data/spec/integration/mongos_pinning_spec.rb +34 -0
  84. data/spec/integration/operation_failure_code_spec.rb +2 -2
  85. data/spec/integration/{read_concern.rb → read_concern_spec.rb} +7 -1
  86. data/spec/integration/read_preference_spec.rb +485 -0
  87. data/spec/integration/retryable_writes_spec.rb +8 -19
  88. data/spec/integration/sdam_error_handling_spec.rb +1 -1
  89. data/spec/integration/sdam_events_spec.rb +2 -2
  90. data/spec/integration/server_description_spec.rb +14 -17
  91. data/spec/integration/server_selector_spec.rb +7 -3
  92. data/spec/integration/server_spec.rb +48 -0
  93. data/spec/integration/ssl_uri_options_spec.rb +1 -1
  94. data/spec/integration/step_down_spec.rb +10 -4
  95. data/spec/integration/transactions_examples_spec.rb +11 -10
  96. data/spec/lite_spec_helper.rb +19 -16
  97. data/spec/mongo/auth/scram/negotiation_spec.rb +11 -8
  98. data/spec/mongo/bulk_write/ordered_combiner_spec.rb +6 -6
  99. data/spec/mongo/bulk_write/unordered_combiner_spec.rb +4 -4
  100. data/spec/mongo/bulk_write_spec.rb +12 -2
  101. data/spec/mongo/client_construction_spec.rb +160 -8
  102. data/spec/mongo/client_spec.rb +5 -4
  103. data/spec/mongo/cluster_spec.rb +6 -6
  104. data/spec/mongo/cluster_time_spec.rb +148 -0
  105. data/spec/mongo/collection/view/aggregation_spec.rb +34 -15
  106. data/spec/mongo/collection/view/change_stream_spec.rb +62 -3
  107. data/spec/mongo/collection/view/map_reduce_spec.rb +7 -5
  108. data/spec/mongo/collection/view/readable_spec.rb +4 -4
  109. data/spec/mongo/collection_spec.rb +331 -14
  110. data/spec/mongo/cursor_spec.rb +117 -5
  111. data/spec/mongo/database_spec.rb +240 -8
  112. data/spec/mongo/error/operation_failure_spec.rb +47 -1
  113. data/spec/mongo/error/parser_spec.rb +160 -23
  114. data/spec/mongo/operation/insert/bulk_spec.rb +2 -1
  115. data/spec/mongo/operation/result_spec.rb +27 -0
  116. data/spec/mongo/operation/update/bulk_spec.rb +1 -0
  117. data/spec/mongo/retryable_spec.rb +2 -0
  118. data/spec/mongo/server/app_metadata_spec.rb +2 -2
  119. data/spec/mongo/server/connection_spec.rb +13 -17
  120. data/spec/mongo/server/monitor/connection_spec.rb +13 -10
  121. data/spec/mongo/server_selector_spec.rb +34 -2
  122. data/spec/mongo/session/session_pool_spec.rb +14 -3
  123. data/spec/mongo/session_spec.rb +3 -3
  124. data/spec/mongo/session_transaction_spec.rb +4 -3
  125. data/spec/mongo/socket/ssl_spec.rb +19 -5
  126. data/spec/mongo/socket_spec.rb +1 -62
  127. data/spec/mongo/uri/srv_protocol_spec.rb +14 -20
  128. data/spec/mongo/uri_option_parsing_spec.rb +94 -8
  129. data/spec/mongo/uri_spec.rb +23 -10
  130. data/spec/mongo/write_concern_spec.rb +56 -3
  131. data/spec/spec_tests/change_streams_spec.rb +2 -1
  132. data/spec/spec_tests/cmap_spec.rb +1 -1
  133. data/spec/spec_tests/crud_spec.rb +12 -2
  134. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +24 -1
  135. data/spec/spec_tests/data/change_streams/change-streams.yml +172 -3
  136. data/spec/spec_tests/data/command_monitoring/bulkWrite.yml +1 -1
  137. data/spec/spec_tests/data/command_monitoring/updateMany.yml +0 -2
  138. data/spec/spec_tests/data/command_monitoring/updateOne.yml +0 -5
  139. data/spec/spec_tests/data/crud/read/aggregate-out.yml +0 -6
  140. data/spec/spec_tests/data/crud/read/count-empty.yml +29 -0
  141. data/spec/spec_tests/data/crud/write/bulkWrite-arrayFilters.yml +1 -0
  142. data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +101 -0
  143. data/spec/spec_tests/data/crud/write/bulkWrite.yml +401 -0
  144. data/spec/spec_tests/data/crud/write/insertMany.yml +58 -2
  145. data/spec/spec_tests/data/crud/write/updateMany-arrayFilters.yml +3 -0
  146. data/spec/spec_tests/data/crud/write/updateOne-arrayFilters.yml +6 -1
  147. data/spec/spec_tests/data/crud_v2/aggregate-merge.yml +103 -0
  148. data/spec/spec_tests/data/crud_v2/aggregate-out-readConcern.yml +110 -0
  149. data/spec/spec_tests/data/crud_v2/bulkWrite-arrayFilters.yml +81 -0
  150. data/spec/spec_tests/data/crud_v2/db-aggregate.yml +38 -0
  151. data/spec/spec_tests/data/crud_v2/updateWithPipelines.yml +92 -0
  152. data/spec/spec_tests/data/retryable_writes/insertOne-serverErrors.yml +2 -2
  153. data/spec/spec_tests/data/transactions/abort.yml +3 -0
  154. data/spec/spec_tests/data/transactions/bulk.yml +3 -8
  155. data/spec/spec_tests/data/transactions/causal-consistency.yml +3 -8
  156. data/spec/spec_tests/data/transactions/commit.yml +3 -1
  157. data/spec/spec_tests/data/transactions/count.yml +3 -0
  158. data/spec/spec_tests/data/transactions/delete.yml +3 -0
  159. data/spec/spec_tests/data/transactions/error-labels.yml +4 -1
  160. data/spec/spec_tests/data/transactions/errors-client.yml +56 -0
  161. data/spec/spec_tests/data/transactions/errors.yml +3 -0
  162. data/spec/spec_tests/data/transactions/findOneAndDelete.yml +3 -0
  163. data/spec/spec_tests/data/transactions/findOneAndReplace.yml +3 -0
  164. data/spec/spec_tests/data/transactions/findOneAndUpdate.yml +3 -0
  165. data/spec/spec_tests/data/transactions/insert.yml +3 -0
  166. data/spec/spec_tests/data/transactions/isolation.yml +3 -0
  167. data/spec/spec_tests/data/transactions/mongos-pin-auto.yml +1671 -0
  168. data/spec/spec_tests/data/transactions/mongos-recovery-token.yml +347 -0
  169. data/spec/spec_tests/data/transactions/pin-mongos.yml +557 -0
  170. data/spec/spec_tests/data/transactions/read-concern.yml +3 -0
  171. data/spec/spec_tests/data/transactions/read-pref.yml +3 -0
  172. data/spec/spec_tests/data/transactions/reads.yml +3 -0
  173. data/spec/spec_tests/data/transactions/retryable-abort.yml +5 -2
  174. data/spec/spec_tests/data/transactions/retryable-commit.yml +4 -1
  175. data/spec/spec_tests/data/transactions/retryable-writes.yml +3 -0
  176. data/spec/spec_tests/data/transactions/run-command.yml +3 -0
  177. data/spec/spec_tests/data/transactions/transaction-options.yml +6 -0
  178. data/spec/spec_tests/data/transactions/update.yml +3 -8
  179. data/spec/spec_tests/data/transactions/write-concern.yml +348 -38
  180. data/spec/spec_tests/data/transactions_api/callback-aborts.yml +6 -0
  181. data/spec/spec_tests/data/transactions_api/callback-commits.yml +5 -0
  182. data/spec/spec_tests/data/transactions_api/callback-retry.yml +7 -2
  183. data/spec/spec_tests/data/transactions_api/commit-retry.yml +70 -15
  184. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +3 -0
  185. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +3 -0
  186. data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +59 -109
  187. data/spec/spec_tests/data/transactions_api/commit.yml +5 -0
  188. data/spec/spec_tests/data/transactions_api/transaction-options.yml +10 -0
  189. data/spec/spec_tests/retryable_reads_spec.rb +5 -2
  190. data/spec/spec_tests/retryable_writes_spec.rb +5 -2
  191. data/spec/spec_tests/sdam_monitoring_spec.rb +3 -3
  192. data/spec/spec_tests/sdam_spec.rb +2 -2
  193. data/spec/spec_tests/transactions_api_spec.rb +1 -67
  194. data/spec/spec_tests/transactions_spec.rb +2 -66
  195. data/spec/support/authorization.rb +4 -0
  196. data/spec/support/change_streams.rb +30 -10
  197. data/spec/support/change_streams/operation.rb +27 -0
  198. data/spec/support/client_registry.rb +44 -25
  199. data/spec/support/cluster_config.rb +25 -14
  200. data/spec/support/cluster_tools.rb +32 -10
  201. data/spec/support/command_monitoring.rb +1 -1
  202. data/spec/support/common_shortcuts.rb +30 -0
  203. data/spec/support/connection_string.rb +8 -3
  204. data/spec/support/constraints.rb +34 -0
  205. data/spec/support/crud.rb +31 -16
  206. data/spec/support/crud/context.rb +23 -0
  207. data/spec/support/crud/operation.rb +311 -14
  208. data/spec/support/crud/spec.rb +2 -1
  209. data/spec/support/crud/test.rb +24 -27
  210. data/spec/support/crud/test_base.rb +22 -0
  211. data/spec/support/crud/verifier.rb +15 -1
  212. data/spec/support/event_subscriber.rb +12 -0
  213. data/spec/support/sdam_formatter_integration.rb +12 -6
  214. data/spec/support/shared/server_selector.rb +10 -0
  215. data/spec/support/shared/session.rb +13 -12
  216. data/spec/support/spec_config.rb +32 -22
  217. data/spec/support/spec_setup.rb +2 -2
  218. data/spec/support/transactions.rb +87 -0
  219. data/spec/support/transactions/context.rb +33 -0
  220. data/spec/support/transactions/operation.rb +99 -349
  221. data/spec/support/transactions/spec.rb +1 -3
  222. data/spec/support/transactions/test.rb +110 -49
  223. data/spec/support/utils.rb +74 -1
  224. metadata +52 -10
  225. metadata.gz.sig +0 -0
  226. data/spec/support/crud/read.rb +0 -265
  227. data/spec/support/crud/write.rb +0 -284
@@ -18,9 +18,7 @@ module Mongo
18
18
  class Spec < Mongo::CRUD::Spec
19
19
  def tests
20
20
  @tests.map do |test|
21
- lambda do
22
- Mongo::Transactions::TransactionsTest.new(@data, test, self)
23
- end
21
+ Mongo::Transactions::TransactionsTest.new(self, @data, test)
24
22
  end
25
23
  end
26
24
  end
@@ -18,7 +18,7 @@ module Mongo
18
18
  # Represents a single transaction test.
19
19
  #
20
20
  # @since 2.6.0
21
- class TransactionsTest
21
+ class TransactionsTest < CRUD::CRUDTestBase
22
22
 
23
23
  # The test description.
24
24
  #
@@ -42,35 +42,57 @@ module Mongo
42
42
  # @example Create the test.
43
43
  # TransactionTest.new(data, test)
44
44
  #
45
+ # @param [ Crud::Spec ] crud_spec The top level YAML specification object.
45
46
  # @param [ Array<Hash> ] data The documents the collection
46
47
  # must have before the test runs.
47
48
  # @param [ Hash ] test The test specification.
48
- # @param [ Hash ] spec The top level YAML specification.
49
49
  #
50
50
  # @since 2.6.0
51
- def initialize(data, test, spec)
51
+ def initialize(crud_spec, data, test)
52
52
  test = IceNine.deep_freeze(test)
53
- @spec = spec
53
+ @spec = crud_spec
54
54
  @data = data
55
55
  @description = test['description']
56
56
  @client_options = Utils.convert_client_options(test['clientOptions'] || {})
57
- @session_options = Utils.snakeize_hash(test['sessionOptions'] || {})
57
+ @session_options = if opts = test['sessionOptions']
58
+ Hash[opts.map do |session_name, options|
59
+ [session_name.to_sym, Utils.convert_operation_options(options)]
60
+ end]
61
+ else
62
+ {}
63
+ end
58
64
  @fail_point = test['failPoint']
65
+ @skip_reason = test['skipReason']
66
+ @multiple_mongoses = test['useMultipleMongoses']
67
+
59
68
  @operations = test['operations']
69
+ @ops = @operations.map do |op|
70
+ Operation.new(self, op)
71
+ end
72
+
60
73
  @expectations = test['expectations']
61
- @skip_reason = test['skipReason']
62
74
  if test['outcome']
63
75
  @outcome = Mongo::CRUD::Outcome.new(test['outcome'])
64
76
  end
65
77
  @expected_results = @operations.map do |o|
66
- result = o['result']
67
- next result unless result.class == Hash
68
-
69
- # Change maps of result ids to arrays of ids
70
- result.dup.tap do |r|
71
- r.each do |k, v|
72
- next unless ['insertedIds', 'upsertedIds'].include?(k)
73
- r[k] = v.to_a.sort_by(&:first).map(&:last)
78
+ # We check both o.key('error') and o['error'] to provide a better
79
+ # error message in case error: false is ever needed in the tests
80
+ if o.key?('error')
81
+ if o['error']
82
+ {'error' => true}
83
+ else
84
+ raise "Unsupported error value #{o['error']}"
85
+ end
86
+ else
87
+ result = o['result']
88
+ next result unless result.class == Hash
89
+
90
+ # Change maps of result ids to arrays of ids
91
+ result.dup.tap do |r|
92
+ r.each do |k, v|
93
+ next unless ['insertedIds', 'upsertedIds'].include?(k)
94
+ r[k] = v.to_a.sort_by(&:first).map(&:last)
95
+ end
74
96
  end
75
97
  end
76
98
  end
@@ -78,6 +100,10 @@ module Mongo
78
100
 
79
101
  attr_reader :outcome
80
102
 
103
+ def multiple_mongoses?
104
+ @multiple_mongoses
105
+ end
106
+
81
107
  def support_client
82
108
  @support_client ||= ClientRegistry.instance.global_client('root_authorized').use(@spec.database_name)
83
109
  end
@@ -87,16 +113,32 @@ module Mongo
87
113
  end
88
114
 
89
115
  def test_client
90
- @test_client ||= ClientRegistry.instance.global_client('authorized_without_retry_writes').with(
91
- @client_options.merge(
92
- database: @spec.database_name,
93
- app_name: 'this is used solely to force the new client to create its own cluster'))
116
+ @test_client ||= ClientRegistry.instance.global_client(
117
+ 'authorized_without_retry_writes'
118
+ ).with(@client_options.merge(
119
+ database: @spec.database_name,
120
+ ))
94
121
  end
95
122
 
96
123
  def event_subscriber
97
124
  @event_subscriber ||= EventSubscriber.new
98
125
  end
99
126
 
127
+ def mongos_each_direct_client
128
+ if ClusterConfig.instance.mongos?
129
+ client = ClientRegistry.instance.global_client('basic')
130
+ client.cluster.next_primary
131
+ client.cluster.servers.each do |server|
132
+ direct_client = ClientRegistry.instance.new_local_client(
133
+ [server.address.to_s],
134
+ SpecConfig.instance.test_options.merge(
135
+ connect: :sharded
136
+ ).merge(SpecConfig.instance.auth_options))
137
+ yield direct_client
138
+ end
139
+ end
140
+ end
141
+
100
142
  # Run the test.
101
143
  #
102
144
  # @example Run the test.
@@ -108,23 +150,9 @@ module Mongo
108
150
  def run
109
151
  test_client.subscribe(Mongo::Monitoring::COMMAND, event_subscriber)
110
152
 
111
- $distinct_ran ||= if @ops.any? { |op| op.name == 'distinct' }
112
- if ClusterConfig.instance.mongos?
113
- client = ClientRegistry.instance.global_client('basic')
114
- client.cluster.next_primary
115
- client.cluster.servers.each do |server|
116
- direct_client = ClientRegistry.instance.new_local_client(
117
- [server.address.to_s],
118
- SpecConfig.instance.test_options.merge(
119
- connect: :sharded
120
- ).merge(SpecConfig.instance.auth_options))
121
- direct_client['test'].distinct('foo').to_a
122
- end
123
- end
124
- end
125
-
126
153
  results = @ops.map do |op|
127
- op.execute(@collection)
154
+ target = resolve_target(test_client, op)
155
+ op.execute(target, @session0, @session1)
128
156
  end
129
157
 
130
158
  session0_id = @session0.session_id
@@ -134,6 +162,9 @@ module Mongo
134
162
  @session1.end_session
135
163
 
136
164
  actual_events = Utils.yamlify_command_events(event_subscriber.started_events)
165
+ actual_events = actual_events.reject do |event|
166
+ event['command_started_event']['command']['endSessions']
167
+ end
137
168
  actual_events.each do |e|
138
169
 
139
170
  # Replace the session id placeholders with the actual session ids.
@@ -143,13 +174,12 @@ module Mongo
143
174
 
144
175
  end
145
176
 
146
- if @fail_point
147
- admin_support_client.command(configureFailPoint: 'failCommand', mode: 'off')
148
- end
149
-
150
177
  @results = {
151
178
  results: results,
152
- contents: @collection.with(read_concern: { level: 'local' }).find.to_a,
179
+ contents: @collection.with(
180
+ read: {mode: 'primary'},
181
+ read_concern: { level: 'local' },
182
+ ).find.to_a,
153
183
  events: actual_events,
154
184
  }
155
185
  end
@@ -160,30 +190,61 @@ module Mongo
160
190
  rescue Mongo::Error
161
191
  end
162
192
 
163
- coll = support_client[@spec.collection_name]
193
+ mongos_each_direct_client do |direct_client|
194
+ direct_client.command(configureFailPoint: 'failCommand', mode: 'off')
195
+ end
196
+
197
+ coll = support_client[@spec.collection_name].with(write: { w: :majority })
164
198
  coll.drop
165
- coll.with(write: { w: :majority }).drop
166
199
  support_client.command(create: @spec.collection_name, writeConcern: { w: :majority })
167
200
 
168
- coll.with(write: { w: :majority }).insert_many(@data) unless @data.empty?
201
+ coll.insert_many(@data) unless @data.empty?
202
+
203
+ $distinct_ran ||= if description =~ /distinct/ || @ops.any? { |op| op.name == 'distinct' }
204
+ mongos_each_direct_client do |direct_client|
205
+ direct_client['test'].distinct('foo').to_a
206
+ end
207
+ end
208
+
169
209
  admin_support_client.command(@fail_point) if @fail_point
170
210
 
171
211
  @collection = test_client[@spec.collection_name]
172
212
 
173
213
  @session0 = test_client.start_session(@session_options[:session0] || {})
174
214
  @session1 = test_client.start_session(@session_options[:session1] || {})
175
-
176
- @ops = @operations.map do |op|
177
- Operation.new(op, @session0, @session1)
178
- end
179
215
  end
180
216
 
181
217
  def teardown_test
182
- if @admin_support_client
183
- @admin_support_client.close
218
+
219
+ if @fail_point
220
+ admin_support_client.command(configureFailPoint: 'failCommand', mode: 'off')
221
+ end
222
+
223
+ if $disable_fail_points
224
+ $disable_fail_points.each do |(fail_point, address)|
225
+ client = ClusterTools.instance.direct_client(address,
226
+ database: 'admin')
227
+ client.command(configureFailPoint: fail_point['configureFailPoint'],
228
+ mode: 'off')
229
+ end
184
230
  end
231
+
185
232
  if @test_client
186
- @test_client.close
233
+ @test_client.cluster.session_pool.end_sessions
234
+ end
235
+ end
236
+
237
+ def resolve_target(client, operation)
238
+ case operation.object
239
+ when 'session0'
240
+ @session0
241
+ when 'session1'
242
+ @session1
243
+ when 'testRunner'
244
+ # We don't actually use this target in any way.
245
+ nil
246
+ else
247
+ super
187
248
  end
188
249
  end
189
250
  end
@@ -3,7 +3,7 @@ module Utils
3
3
  # Converts a 'camelCase' string or symbol to a :under_score symbol.
4
4
  def underscore(str)
5
5
  str = str.to_s
6
- str = str[0].downcase + str[1...str.length].gsub(/([A-Z])/) { |m| "_#{m.downcase}" }
6
+ str = str[0].downcase + str[1...str.length].gsub(/([A-Z]+)/) { |m| "_#{m.downcase}" }
7
7
  str.to_sym
8
8
  end
9
9
  module_function :underscore
@@ -23,6 +23,28 @@ module Utils
23
23
  end
24
24
  module_function :snakeize_hash
25
25
 
26
+ # Like snakeize_hash but does not recurse.
27
+ def shallow_snakeize_hash(value)
28
+ return underscore(value) if value.is_a?(String)
29
+ return value unless value.is_a?(Hash)
30
+
31
+ value.reduce({}) do |hash, (k, v)|
32
+ hash.tap do |h|
33
+ h[underscore(k)] = v
34
+ end
35
+ end
36
+ end
37
+ module_function :shallow_snakeize_hash
38
+
39
+ def camelize(str, upcase_first = true)
40
+ str = str.gsub(%r,_(\w),) { |m| m[1].upcase }
41
+ if upcase_first
42
+ str = str[0].upcase + str[1...str.length]
43
+ end
44
+ str
45
+ end
46
+ module_function :camelize
47
+
26
48
  # Converts camel case clientOptions, as used in spec tests,
27
49
  # to Ruby driver underscore options.
28
50
  def convert_client_options(spec_test_options)
@@ -78,6 +100,10 @@ module Utils
78
100
  end
79
101
  end
80
102
 
103
+ if command['recoveryToken']
104
+ command['recoveryToken'] = 42
105
+ end
106
+
81
107
  # The spec tests use 42 as a placeholder value for any getMore cursorId.
82
108
  command['getMore'] = { '$numberLong' => '42' } if command['getMore']
83
109
 
@@ -111,4 +137,51 @@ module Utils
111
137
  events
112
138
  end
113
139
  module_function :yamlify_command_events
140
+
141
+ def convert_operation_options(options)
142
+ if options
143
+ Hash[options.map do |k, v|
144
+ out_v = case k
145
+ when 'readPreference'
146
+ out_k = :read
147
+ out_v = {}
148
+ v.each do |sub_k, sub_v|
149
+ if sub_k == 'mode'
150
+ out_v[:mode] = Utils.underscore(v['mode'])
151
+ else
152
+ out_v[sub_k.to_sym] = sub_v
153
+ end
154
+ end
155
+ out_v
156
+ when 'defaultTransactionOptions'
157
+ out_k = Utils.underscore(k).to_sym
158
+ convert_operation_options(v)
159
+ when 'readConcern'
160
+ out_k = Utils.underscore(k).to_sym
161
+ Mongo::Options::Mapper.transform_keys_to_symbols(v).tap do |out|
162
+ if out[:level]
163
+ out[:level] = out[:level].to_sym
164
+ end
165
+ end
166
+ when 'causalConsistency'
167
+ out_k = Utils.underscore(k).to_sym
168
+ v
169
+ when 'writeConcern'
170
+ # Write concern option is called :write on the client, but
171
+ # :write_concern on all levels below the client.
172
+ out_k = :write_concern
173
+ # The client expects write concern value to only have symbol keys.
174
+ Hash[v.map do |sub_k, sub_v|
175
+ [sub_k.to_sym, sub_v]
176
+ end]
177
+ else
178
+ raise "Unhandled operation option #{k}"
179
+ end
180
+ [out_k, out_v]
181
+ end]
182
+ else
183
+ {}
184
+ end
185
+ end
186
+ module_function :convert_operation_options
114
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.2
4
+ version: 2.10.0.rc0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -31,7 +31,7 @@ cert_chain:
31
31
  bMYVwXXhV8czdzgkQB/ZPWHSbEWXnmkze1mzvqWBCPOVXYrcnL9cnEl/RoxtS1hr
32
32
  Db6Ac6mCUSYfYHBWpWqxjc45n70i5Xi1
33
33
  -----END CERTIFICATE-----
34
- date: 2019-09-23 00:00:00.000000000 Z
34
+ date: 2019-08-06 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bson
@@ -111,6 +111,7 @@ files:
111
111
  - lib/mongo/cluster/topology/sharded.rb
112
112
  - lib/mongo/cluster/topology/single.rb
113
113
  - lib/mongo/cluster/topology/unknown.rb
114
+ - lib/mongo/cluster_time.rb
114
115
  - lib/mongo/collection.rb
115
116
  - lib/mongo/collection/view.rb
116
117
  - lib/mongo/collection/view/aggregation.rb
@@ -358,6 +359,7 @@ files:
358
359
  - lib/mongo/operation/shared/result/use_legacy_error_parser.rb
359
360
  - lib/mongo/operation/shared/sessions_supported.rb
360
361
  - lib/mongo/operation/shared/specifiable.rb
362
+ - lib/mongo/operation/shared/unpinnable.rb
361
363
  - lib/mongo/operation/shared/write.rb
362
364
  - lib/mongo/operation/shared/write_concern_supported.rb
363
365
  - lib/mongo/operation/update.rb
@@ -431,6 +433,7 @@ files:
431
433
  - mongo.gemspec
432
434
  - spec/README.md
433
435
  - spec/atlas/atlas_connectivity_spec.rb
436
+ - spec/atlas/operations_spec.rb
434
437
  - spec/enterprise_auth/kerberos_spec.rb
435
438
  - spec/integration/auth_spec.rb
436
439
  - spec/integration/bulk_insert_spec.rb
@@ -438,6 +441,7 @@ files:
438
441
  - spec/integration/change_stream_spec.rb
439
442
  - spec/integration/client_connectivity_spec.rb
440
443
  - spec/integration/client_construction_spec.rb
444
+ - spec/integration/client_spec.rb
441
445
  - spec/integration/command_monitoring_spec.rb
442
446
  - spec/integration/command_spec.rb
443
447
  - spec/integration/connect_single_rs_name_spec.rb
@@ -446,14 +450,18 @@ files:
446
450
  - spec/integration/docs_examples_spec.rb
447
451
  - spec/integration/error_detection_spec.rb
448
452
  - spec/integration/heartbeat_events_spec.rb
453
+ - spec/integration/mmapv1_spec.rb
454
+ - spec/integration/mongos_pinning_spec.rb
449
455
  - spec/integration/operation_failure_code_spec.rb
450
- - spec/integration/read_concern.rb
456
+ - spec/integration/read_concern_spec.rb
457
+ - spec/integration/read_preference_spec.rb
451
458
  - spec/integration/reconnect_spec.rb
452
459
  - spec/integration/retryable_writes_spec.rb
453
460
  - spec/integration/sdam_error_handling_spec.rb
454
461
  - spec/integration/sdam_events_spec.rb
455
462
  - spec/integration/server_description_spec.rb
456
463
  - spec/integration/server_selector_spec.rb
464
+ - spec/integration/server_spec.rb
457
465
  - spec/integration/shell_examples_spec.rb
458
466
  - spec/integration/ssl_uri_options_spec.rb
459
467
  - spec/integration/step_down_spec.rb
@@ -493,6 +501,7 @@ files:
493
501
  - spec/mongo/cluster/topology/unknown_spec.rb
494
502
  - spec/mongo/cluster/topology_spec.rb
495
503
  - spec/mongo/cluster_spec.rb
504
+ - spec/mongo/cluster_time_spec.rb
496
505
  - spec/mongo/collection/view/aggregation_spec.rb
497
506
  - spec/mongo/collection/view/builder/find_command_spec.rb
498
507
  - spec/mongo/collection/view/builder/flags_spec.rb
@@ -675,12 +684,15 @@ files:
675
684
  - spec/spec_tests/data/crud/read/aggregate-out.yml
676
685
  - spec/spec_tests/data/crud/read/aggregate.yml
677
686
  - spec/spec_tests/data/crud/read/count-collation.yml
687
+ - spec/spec_tests/data/crud/read/count-empty.yml
678
688
  - spec/spec_tests/data/crud/read/count.yml
679
689
  - spec/spec_tests/data/crud/read/distinct-collation.yml
680
690
  - spec/spec_tests/data/crud/read/distinct.yml
681
691
  - spec/spec_tests/data/crud/read/find-collation.yml
682
692
  - spec/spec_tests/data/crud/read/find.yml
683
693
  - spec/spec_tests/data/crud/write/bulkWrite-arrayFilters.yml
694
+ - spec/spec_tests/data/crud/write/bulkWrite-collation.yml
695
+ - spec/spec_tests/data/crud/write/bulkWrite.yml
684
696
  - spec/spec_tests/data/crud/write/deleteMany-collation.yml
685
697
  - spec/spec_tests/data/crud/write/deleteMany.yml
686
698
  - spec/spec_tests/data/crud/write/deleteOne-collation.yml
@@ -708,6 +720,11 @@ files:
708
720
  - spec/spec_tests/data/crud/write/updateOne-collation.yml
709
721
  - spec/spec_tests/data/crud/write/updateOne-pre_2.6.yml
710
722
  - spec/spec_tests/data/crud/write/updateOne.yml
723
+ - spec/spec_tests/data/crud_v2/aggregate-merge.yml
724
+ - spec/spec_tests/data/crud_v2/aggregate-out-readConcern.yml
725
+ - spec/spec_tests/data/crud_v2/bulkWrite-arrayFilters.yml
726
+ - spec/spec_tests/data/crud_v2/db-aggregate.yml
727
+ - spec/spec_tests/data/crud_v2/updateWithPipelines.yml
711
728
  - spec/spec_tests/data/dns_seedlist_discovery/longer-parent-in-return.yml
712
729
  - spec/spec_tests/data/dns_seedlist_discovery/misformatted-option.yml
713
730
  - spec/spec_tests/data/dns_seedlist_discovery/no-results.yml
@@ -964,12 +981,16 @@ files:
964
981
  - spec/spec_tests/data/transactions/count.yml
965
982
  - spec/spec_tests/data/transactions/delete.yml
966
983
  - spec/spec_tests/data/transactions/error-labels.yml
984
+ - spec/spec_tests/data/transactions/errors-client.yml
967
985
  - spec/spec_tests/data/transactions/errors.yml
968
986
  - spec/spec_tests/data/transactions/findOneAndDelete.yml
969
987
  - spec/spec_tests/data/transactions/findOneAndReplace.yml
970
988
  - spec/spec_tests/data/transactions/findOneAndUpdate.yml
971
989
  - spec/spec_tests/data/transactions/insert.yml
972
990
  - spec/spec_tests/data/transactions/isolation.yml
991
+ - spec/spec_tests/data/transactions/mongos-pin-auto.yml
992
+ - spec/spec_tests/data/transactions/mongos-recovery-token.yml
993
+ - spec/spec_tests/data/transactions/pin-mongos.yml
973
994
  - spec/spec_tests/data/transactions/read-concern.yml
974
995
  - spec/spec_tests/data/transactions/read-pref.yml
975
996
  - spec/spec_tests/data/transactions/reads.yml
@@ -1043,14 +1064,14 @@ files:
1043
1064
  - spec/support/connection_string.rb
1044
1065
  - spec/support/constraints.rb
1045
1066
  - spec/support/crud.rb
1067
+ - spec/support/crud/context.rb
1046
1068
  - spec/support/crud/operation.rb
1047
1069
  - spec/support/crud/outcome.rb
1048
- - spec/support/crud/read.rb
1049
1070
  - spec/support/crud/requirement.rb
1050
1071
  - spec/support/crud/spec.rb
1051
1072
  - spec/support/crud/test.rb
1073
+ - spec/support/crud/test_base.rb
1052
1074
  - spec/support/crud/verifier.rb
1053
- - spec/support/crud/write.rb
1054
1075
  - spec/support/event_subscriber.rb
1055
1076
  - spec/support/gridfs.rb
1056
1077
  - spec/support/json_ext_formatter.rb
@@ -1069,6 +1090,7 @@ files:
1069
1090
  - spec/support/spec_config.rb
1070
1091
  - spec/support/spec_setup.rb
1071
1092
  - spec/support/transactions.rb
1093
+ - spec/support/transactions/context.rb
1072
1094
  - spec/support/transactions/operation.rb
1073
1095
  - spec/support/transactions/spec.rb
1074
1096
  - spec/support/transactions/test.rb
@@ -1088,9 +1110,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
1088
1110
  version: '0'
1089
1111
  required_rubygems_version: !ruby/object:Gem::Requirement
1090
1112
  requirements:
1091
- - - ">="
1113
+ - - ">"
1092
1114
  - !ruby/object:Gem::Version
1093
- version: '0'
1115
+ version: 1.3.1
1094
1116
  requirements: []
1095
1117
  rubygems_version: 3.0.3
1096
1118
  signing_key:
@@ -1136,14 +1158,14 @@ test_files:
1136
1158
  - spec/support/shared/session.rb
1137
1159
  - spec/support/cmap.rb
1138
1160
  - spec/support/authorization.rb
1139
- - spec/support/crud/read.rb
1140
1161
  - spec/support/crud/spec.rb
1162
+ - spec/support/crud/test_base.rb
1163
+ - spec/support/crud/context.rb
1141
1164
  - spec/support/crud/operation.rb
1142
1165
  - spec/support/crud/test.rb
1143
1166
  - spec/support/crud/verifier.rb
1144
1167
  - spec/support/crud/requirement.rb
1145
1168
  - spec/support/crud/outcome.rb
1146
- - spec/support/crud/write.rb
1147
1169
  - spec/support/common_shortcuts.rb
1148
1170
  - spec/support/monitoring_ext.rb
1149
1171
  - spec/support/client_registry_macros.rb
@@ -1158,6 +1180,7 @@ test_files:
1158
1180
  - spec/support/transactions.rb
1159
1181
  - spec/support/cluster_tools.rb
1160
1182
  - spec/support/transactions/spec.rb
1183
+ - spec/support/transactions/context.rb
1161
1184
  - spec/support/transactions/operation.rb
1162
1185
  - spec/support/transactions/test.rb
1163
1186
  - spec/support/spec_setup.rb
@@ -1165,21 +1188,25 @@ test_files:
1165
1188
  - spec/README.md
1166
1189
  - spec/integration/ssl_uri_options_spec.rb
1167
1190
  - spec/integration/step_down_spec.rb
1168
- - spec/integration/read_concern.rb
1191
+ - spec/integration/read_concern_spec.rb
1169
1192
  - spec/integration/server_description_spec.rb
1170
1193
  - spec/integration/connection_spec.rb
1171
1194
  - spec/integration/operation_failure_code_spec.rb
1172
1195
  - spec/integration/error_detection_spec.rb
1173
1196
  - spec/integration/connect_single_rs_name_spec.rb
1197
+ - spec/integration/mmapv1_spec.rb
1174
1198
  - spec/integration/sdam_events_spec.rb
1175
1199
  - spec/integration/shell_examples_spec.rb
1176
1200
  - spec/integration/cursor_reaping_spec.rb
1201
+ - spec/integration/client_spec.rb
1202
+ - spec/integration/server_spec.rb
1177
1203
  - spec/integration/client_construction_spec.rb
1178
1204
  - spec/integration/server_selector_spec.rb
1179
1205
  - spec/integration/retryable_writes_spec.rb
1180
1206
  - spec/integration/change_stream_examples_spec.rb
1181
1207
  - spec/integration/transactions_examples_spec.rb
1182
1208
  - spec/integration/command_monitoring_spec.rb
1209
+ - spec/integration/read_preference_spec.rb
1183
1210
  - spec/integration/reconnect_spec.rb
1184
1211
  - spec/integration/client_connectivity_spec.rb
1185
1212
  - spec/integration/bulk_insert_spec.rb
@@ -1187,6 +1214,7 @@ test_files:
1187
1214
  - spec/integration/command_spec.rb
1188
1215
  - spec/integration/change_stream_spec.rb
1189
1216
  - spec/integration/time_zone_querying_spec.rb
1217
+ - spec/integration/mongos_pinning_spec.rb
1190
1218
  - spec/integration/heartbeat_events_spec.rb
1191
1219
  - spec/integration/docs_examples_spec.rb
1192
1220
  - spec/integration/sdam_error_handling_spec.rb
@@ -1227,6 +1255,7 @@ test_files:
1227
1255
  - spec/mongo/uri_option_parsing_spec.rb
1228
1256
  - spec/mongo/lint_spec.rb
1229
1257
  - spec/mongo/dbref_spec.rb
1258
+ - spec/mongo/cluster_time_spec.rb
1230
1259
  - spec/mongo/options/redacted_spec.rb
1231
1260
  - spec/mongo/client_spec.rb
1232
1261
  - spec/mongo/server_spec.rb
@@ -1356,6 +1385,7 @@ test_files:
1356
1385
  - spec/mongo/event/publisher_spec.rb
1357
1386
  - spec/mongo/event/subscriber_spec.rb
1358
1387
  - spec/mongo/uri/srv_protocol_spec.rb
1388
+ - spec/atlas/operations_spec.rb
1359
1389
  - spec/atlas/atlas_connectivity_spec.rb
1360
1390
  - spec/enterprise_auth/kerberos_spec.rb
1361
1391
  - spec/lite_spec_helper.rb
@@ -1519,14 +1549,21 @@ test_files:
1519
1549
  - spec/spec_tests/data/uri_options/connection-pool-options.yml
1520
1550
  - spec/spec_tests/data/uri_options/read-preference-options.yml
1521
1551
  - spec/spec_tests/data/uri_options/concern-options.yml
1552
+ - spec/spec_tests/data/crud_v2/bulkWrite-arrayFilters.yml
1553
+ - spec/spec_tests/data/crud_v2/updateWithPipelines.yml
1554
+ - spec/spec_tests/data/crud_v2/aggregate-merge.yml
1555
+ - spec/spec_tests/data/crud_v2/db-aggregate.yml
1556
+ - spec/spec_tests/data/crud_v2/aggregate-out-readConcern.yml
1522
1557
  - spec/spec_tests/data/crud/write/findOneAndUpdate-collation.yml
1523
1558
  - spec/spec_tests/data/crud/write/findOneAndReplace-upsert.yml
1524
1559
  - spec/spec_tests/data/crud/write/findOneAndDelete.yml
1560
+ - spec/spec_tests/data/crud/write/bulkWrite-collation.yml
1525
1561
  - spec/spec_tests/data/crud/write/deleteMany.yml
1526
1562
  - spec/spec_tests/data/crud/write/deleteOne-collation.yml
1527
1563
  - spec/spec_tests/data/crud/write/replaceOne-pre_2.6.yml
1528
1564
  - spec/spec_tests/data/crud/write/deleteMany-collation.yml
1529
1565
  - spec/spec_tests/data/crud/write/findOneAndDelete-collation.yml
1566
+ - spec/spec_tests/data/crud/write/bulkWrite.yml
1530
1567
  - spec/spec_tests/data/crud/write/updateOne.yml
1531
1568
  - spec/spec_tests/data/crud/write/bulkWrite-arrayFilters.yml
1532
1569
  - spec/spec_tests/data/crud/write/updateMany-arrayFilters.yml
@@ -1551,6 +1588,7 @@ test_files:
1551
1588
  - spec/spec_tests/data/crud/read/distinct-collation.yml
1552
1589
  - spec/spec_tests/data/crud/read/find.yml
1553
1590
  - spec/spec_tests/data/crud/read/count.yml
1591
+ - spec/spec_tests/data/crud/read/count-empty.yml
1554
1592
  - spec/spec_tests/data/crud/read/aggregate-out.yml
1555
1593
  - spec/spec_tests/data/crud/read/find-collation.yml
1556
1594
  - spec/spec_tests/data/crud/read/aggregate.yml
@@ -1706,12 +1744,15 @@ test_files:
1706
1744
  - spec/spec_tests/data/transactions/isolation.yml
1707
1745
  - spec/spec_tests/data/transactions/transaction-options.yml
1708
1746
  - spec/spec_tests/data/transactions/write-concern.yml
1747
+ - spec/spec_tests/data/transactions/errors-client.yml
1709
1748
  - spec/spec_tests/data/transactions/read-pref.yml
1710
1749
  - spec/spec_tests/data/transactions/findOneAndDelete.yml
1750
+ - spec/spec_tests/data/transactions/mongos-pin-auto.yml
1711
1751
  - spec/spec_tests/data/transactions/error-labels.yml
1712
1752
  - spec/spec_tests/data/transactions/retryable-commit.yml
1713
1753
  - spec/spec_tests/data/transactions/read-concern.yml
1714
1754
  - spec/spec_tests/data/transactions/bulk.yml
1755
+ - spec/spec_tests/data/transactions/pin-mongos.yml
1715
1756
  - spec/spec_tests/data/transactions/reads.yml
1716
1757
  - spec/spec_tests/data/transactions/count.yml
1717
1758
  - spec/spec_tests/data/transactions/findOneAndReplace.yml
@@ -1723,6 +1764,7 @@ test_files:
1723
1764
  - spec/spec_tests/data/transactions/causal-consistency.yml
1724
1765
  - spec/spec_tests/data/transactions/run-command.yml
1725
1766
  - spec/spec_tests/data/transactions/delete.yml
1767
+ - spec/spec_tests/data/transactions/mongos-recovery-token.yml
1726
1768
  - spec/spec_tests/data/transactions/commit.yml
1727
1769
  - spec/spec_tests/crud_spec.rb
1728
1770
  - spec/spec_tests/max_staleness_spec.rb