mongo 2.14.1 → 2.15.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +4 -1
  4. data/Rakefile +8 -15
  5. data/lib/mongo/auth/aws/conversation.rb +1 -4
  6. data/lib/mongo/auth/base.rb +13 -7
  7. data/lib/mongo/auth/conversation_base.rb +32 -0
  8. data/lib/mongo/auth/cr/conversation.rb +6 -29
  9. data/lib/mongo/auth/gssapi/conversation.rb +4 -15
  10. data/lib/mongo/auth/ldap/conversation.rb +3 -14
  11. data/lib/mongo/auth/sasl_conversation_base.rb +1 -13
  12. data/lib/mongo/auth/scram_conversation_base.rb +7 -34
  13. data/lib/mongo/auth/user/view.rb +16 -9
  14. data/lib/mongo/auth/x509/conversation.rb +4 -25
  15. data/lib/mongo/bulk_write.rb +21 -18
  16. data/lib/mongo/client.rb +82 -6
  17. data/lib/mongo/cluster/reapers/cursor_reaper.rb +6 -2
  18. data/lib/mongo/cluster.rb +19 -2
  19. data/lib/mongo/collection/view/aggregation.rb +1 -1
  20. data/lib/mongo/collection/view/change_stream.rb +1 -1
  21. data/lib/mongo/collection/view/iterable.rb +7 -17
  22. data/lib/mongo/collection/view/map_reduce.rb +2 -2
  23. data/lib/mongo/collection/view/readable.rb +42 -20
  24. data/lib/mongo/collection/view/writable.rb +14 -14
  25. data/lib/mongo/collection.rb +6 -6
  26. data/lib/mongo/cursor.rb +2 -12
  27. data/lib/mongo/database/view.rb +1 -1
  28. data/lib/mongo/database.rb +8 -3
  29. data/lib/mongo/error/bulk_write_error.rb +17 -3
  30. data/lib/mongo/error/internal_driver_error.rb +22 -0
  31. data/lib/mongo/error/operation_failure.rb +21 -2
  32. data/lib/mongo/error/parser.rb +65 -12
  33. data/lib/mongo/error/server_api_conflict.rb +23 -0
  34. data/lib/mongo/error/server_api_not_supported.rb +24 -0
  35. data/lib/mongo/error/unmet_dependency.rb +21 -0
  36. data/lib/mongo/error.rb +9 -1
  37. data/lib/mongo/index/view.rb +21 -11
  38. data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +27 -16
  39. data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +26 -15
  40. data/lib/mongo/monitoring.rb +13 -4
  41. data/lib/mongo/operation/collections_info/command.rb +2 -2
  42. data/lib/mongo/operation/collections_info.rb +18 -1
  43. data/lib/mongo/operation/context.rb +99 -0
  44. data/lib/mongo/operation/indexes.rb +15 -1
  45. data/lib/mongo/operation/insert/command.rb +2 -2
  46. data/lib/mongo/operation/insert/legacy.rb +2 -2
  47. data/lib/mongo/operation/insert/op_msg.rb +2 -2
  48. data/lib/mongo/operation/list_collections/result.rb +4 -1
  49. data/lib/mongo/operation/parallel_scan/command.rb +2 -1
  50. data/lib/mongo/operation/result.rb +2 -0
  51. data/lib/mongo/operation/shared/executable.rb +24 -14
  52. data/lib/mongo/operation/shared/executable_no_validate.rb +2 -2
  53. data/lib/mongo/operation/shared/op_msg_or_command.rb +1 -7
  54. data/lib/mongo/operation/shared/op_msg_or_find_command.rb +1 -7
  55. data/lib/mongo/operation/shared/polymorphic_operation.rb +39 -0
  56. data/lib/mongo/operation/shared/read_preference_supported.rb +36 -38
  57. data/lib/mongo/operation/shared/response_handling.rb +23 -23
  58. data/lib/mongo/operation/shared/sessions_supported.rb +15 -5
  59. data/lib/mongo/operation/shared/write.rb +8 -18
  60. data/lib/mongo/operation.rb +2 -2
  61. data/lib/mongo/protocol/compressed.rb +51 -5
  62. data/lib/mongo/protocol/message.rb +20 -2
  63. data/lib/mongo/protocol/msg.rb +38 -13
  64. data/lib/mongo/protocol/query.rb +11 -11
  65. data/lib/mongo/query_cache.rb +30 -0
  66. data/lib/mongo/retryable.rb +1 -1
  67. data/lib/mongo/server/app_metadata.rb +52 -18
  68. data/lib/mongo/server/connection.rb +5 -0
  69. data/lib/mongo/server/connection_base.rb +13 -10
  70. data/lib/mongo/server/connection_pool.rb +6 -2
  71. data/lib/mongo/server/description/features.rb +9 -8
  72. data/lib/mongo/server/description.rb +4 -0
  73. data/lib/mongo/server/monitor/app_metadata.rb +1 -1
  74. data/lib/mongo/server/monitor/connection.rb +9 -10
  75. data/lib/mongo/server/monitor.rb +20 -1
  76. data/lib/mongo/server/pending_connection.rb +24 -6
  77. data/lib/mongo/server/push_monitor.rb +11 -1
  78. data/lib/mongo/server.rb +7 -1
  79. data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
  80. data/lib/mongo/session/session_pool.rb +4 -2
  81. data/lib/mongo/session.rb +2 -2
  82. data/lib/mongo/socket/ssl.rb +8 -0
  83. data/lib/mongo/socket.rb +29 -4
  84. data/lib/mongo/uri/options_mapper.rb +38 -0
  85. data/lib/mongo/utils.rb +15 -0
  86. data/lib/mongo/version.rb +1 -1
  87. data/lib/mongo.rb +23 -0
  88. data/spec/README.md +24 -1
  89. data/spec/integration/auth_spec.rb +25 -15
  90. data/spec/integration/bulk_write_error_message_spec.rb +41 -0
  91. data/spec/integration/change_stream_spec.rb +4 -4
  92. data/spec/integration/command_monitoring_spec.rb +2 -2
  93. data/spec/integration/connection_spec.rb +2 -0
  94. data/spec/integration/docs_examples_spec.rb +8 -1
  95. data/spec/integration/fork_reconnect_spec.rb +4 -1
  96. data/spec/integration/ocsp_verifier_spec.rb +13 -7
  97. data/spec/integration/operation_failure_code_spec.rb +1 -1
  98. data/spec/integration/operation_failure_message_spec.rb +90 -0
  99. data/spec/integration/query_cache_spec.rb +0 -45
  100. data/spec/integration/reconnect_spec.rb +1 -1
  101. data/spec/integration/snappy_compression_spec.rb +25 -0
  102. data/spec/integration/srv_monitoring_spec.rb +1 -1
  103. data/spec/integration/transactions_examples_spec.rb +6 -0
  104. data/spec/integration/zlib_compression_spec.rb +1 -1
  105. data/spec/integration/zstd_compression_spec.rb +26 -0
  106. data/spec/lite_spec_helper.rb +7 -1
  107. data/spec/mongo/address_spec.rb +15 -11
  108. data/spec/mongo/auth/ldap/conversation_spec.rb +1 -1
  109. data/spec/mongo/auth/ldap_spec.rb +5 -1
  110. data/spec/mongo/auth/scram_negotiation_spec.rb +1 -1
  111. data/spec/mongo/auth/scram_spec.rb +1 -1
  112. data/spec/mongo/auth/x509/conversation_spec.rb +3 -3
  113. data/spec/mongo/client_construction_spec.rb +207 -33
  114. data/spec/mongo/client_spec.rb +17 -0
  115. data/spec/mongo/cluster_spec.rb +1 -0
  116. data/spec/mongo/collection/view/explainable_spec.rb +1 -1
  117. data/spec/mongo/collection/view/readable_spec.rb +33 -19
  118. data/spec/mongo/collection_crud_spec.rb +4357 -0
  119. data/spec/mongo/collection_ddl_spec.rb +534 -0
  120. data/spec/mongo/collection_spec.rb +5 -4859
  121. data/spec/mongo/database_spec.rb +66 -4
  122. data/spec/mongo/error/bulk_write_error_spec.rb +3 -3
  123. data/spec/mongo/error/parser_spec.rb +37 -6
  124. data/spec/mongo/index/view_spec.rb +4 -0
  125. data/spec/mongo/monitoring/event/server_heartbeat_failed_spec.rb +1 -1
  126. data/spec/mongo/monitoring/event/server_heartbeat_succeeded_spec.rb +1 -1
  127. data/spec/mongo/operation/aggregate_spec.rb +2 -1
  128. data/spec/mongo/operation/collections_info_spec.rb +4 -1
  129. data/spec/mongo/operation/command_spec.rb +6 -3
  130. data/spec/mongo/operation/create_index_spec.rb +6 -3
  131. data/spec/mongo/operation/create_user_spec.rb +6 -3
  132. data/spec/mongo/operation/delete/bulk_spec.rb +9 -6
  133. data/spec/mongo/operation/delete_spec.rb +11 -7
  134. data/spec/mongo/operation/drop_index_spec.rb +6 -2
  135. data/spec/mongo/operation/find/legacy_spec.rb +3 -1
  136. data/spec/mongo/operation/get_more_spec.rb +3 -1
  137. data/spec/mongo/operation/indexes_spec.rb +5 -1
  138. data/spec/mongo/operation/insert/bulk_spec.rb +10 -7
  139. data/spec/mongo/operation/insert_spec.rb +15 -12
  140. data/spec/mongo/operation/map_reduce_spec.rb +5 -2
  141. data/spec/mongo/operation/read_preference_legacy_spec.rb +19 -9
  142. data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
  143. data/spec/mongo/operation/remove_user_spec.rb +6 -3
  144. data/spec/mongo/operation/result_spec.rb +1 -1
  145. data/spec/mongo/operation/update/bulk_spec.rb +9 -6
  146. data/spec/mongo/operation/update_spec.rb +10 -7
  147. data/spec/mongo/operation/update_user_spec.rb +4 -1
  148. data/spec/mongo/protocol/compressed_spec.rb +26 -12
  149. data/spec/mongo/query_cache_middleware_spec.rb +55 -0
  150. data/spec/mongo/retryable_spec.rb +3 -2
  151. data/spec/mongo/server/app_metadata_shared.rb +7 -33
  152. data/spec/mongo/server/app_metadata_spec.rb +2 -0
  153. data/spec/mongo/server/connection_pool/populator_spec.rb +3 -1
  154. data/spec/mongo/server/connection_pool_spec.rb +1 -1
  155. data/spec/mongo/server/connection_spec.rb +24 -17
  156. data/spec/mongo/server/monitor/connection_spec.rb +17 -7
  157. data/spec/mongo/server/monitor_spec.rb +9 -1
  158. data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
  159. data/spec/mongo/server_spec.rb +15 -2
  160. data/spec/mongo/socket/ssl_spec.rb +40 -0
  161. data/spec/mongo/socket_spec.rb +2 -2
  162. data/spec/mongo/tls_context_hooks_spec.rb +37 -0
  163. data/spec/runners/connection_string.rb +0 -4
  164. data/spec/runners/crud/requirement.rb +40 -3
  165. data/spec/runners/crud/verifier.rb +8 -0
  166. data/spec/runners/transactions/operation.rb +1 -1
  167. data/spec/runners/transactions/test.rb +1 -0
  168. data/spec/runners/unified/assertions.rb +249 -0
  169. data/spec/runners/unified/change_stream_operations.rb +26 -0
  170. data/spec/runners/unified/crud_operations.rb +199 -0
  171. data/spec/runners/unified/ddl_operations.rb +96 -0
  172. data/spec/runners/unified/entity_map.rb +39 -0
  173. data/spec/runners/unified/error.rb +25 -0
  174. data/spec/runners/unified/event_subscriber.rb +91 -0
  175. data/spec/runners/unified/exceptions.rb +21 -0
  176. data/spec/runners/unified/grid_fs_operations.rb +55 -0
  177. data/spec/runners/unified/support_operations.rb +250 -0
  178. data/spec/runners/unified/test.rb +393 -0
  179. data/spec/runners/unified/test_group.rb +28 -0
  180. data/spec/runners/unified/using_hash.rb +31 -0
  181. data/spec/runners/unified.rb +96 -0
  182. data/spec/shared/lib/mrss/cluster_config.rb +0 -3
  183. data/spec/shared/lib/mrss/docker_runner.rb +0 -3
  184. data/spec/shared/lib/mrss/lite_constraints.rb +0 -16
  185. data/spec/shared/lib/mrss/server_version_registry.rb +0 -3
  186. data/spec/shared/lib/mrss/spec_organizer.rb +0 -3
  187. data/spec/shared/shlib/server.sh +1 -1
  188. data/spec/spec_helper.rb +4 -1
  189. data/spec/spec_tests/crud_unified_spec.rb +10 -0
  190. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
  191. data/spec/spec_tests/data/crud_unified/estimatedDocumentCount.yml +267 -0
  192. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-4.9.yml +60 -0
  193. data/spec/spec_tests/data/retryable_reads/{estimatedDocumentCount.yml → estimatedDocumentCount-pre4.9.yml} +2 -0
  194. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-serverErrors-4.9.yml +146 -0
  195. data/spec/spec_tests/data/retryable_reads/{estimatedDocumentCount-serverErrors.yml → estimatedDocumentCount-serverErrors-pre4.9.yml} +2 -0
  196. data/spec/spec_tests/data/retryable_reads/listIndexNames.yml +1 -1
  197. data/spec/spec_tests/data/unified/valid-fail/operation-failure.yml +31 -0
  198. data/spec/spec_tests/data/unified/valid-pass/poc-change-streams.yml +220 -0
  199. data/spec/spec_tests/data/unified/valid-pass/poc-command-monitoring.yml +102 -0
  200. data/spec/spec_tests/data/unified/valid-pass/poc-crud.yml +184 -0
  201. data/spec/spec_tests/data/unified/valid-pass/poc-gridfs.yml +155 -0
  202. data/spec/spec_tests/data/unified/valid-pass/poc-retryable-reads.yml +193 -0
  203. data/spec/spec_tests/data/unified/valid-pass/poc-retryable-writes.yml +210 -0
  204. data/spec/spec_tests/data/unified/valid-pass/poc-sessions.yml +215 -0
  205. data/spec/spec_tests/data/unified/valid-pass/poc-transactions-convenient-api.yml +235 -0
  206. data/spec/spec_tests/data/unified/valid-pass/poc-transactions-mongos-pin-auto.yml +169 -0
  207. data/spec/spec_tests/data/unified/valid-pass/poc-transactions.yml +170 -0
  208. data/spec/spec_tests/data/uri_options/compression-options.yml +1 -1
  209. data/spec/spec_tests/data/versioned_api/crud-api-version-1-strict.yml +416 -0
  210. data/spec/spec_tests/data/versioned_api/crud-api-version-1.yml +409 -0
  211. data/spec/spec_tests/data/versioned_api/runcommand-helper-no-api-version-declared.yml +67 -0
  212. data/spec/spec_tests/data/versioned_api/test-commands-deprecation-errors.yml +47 -0
  213. data/spec/spec_tests/data/versioned_api/test-commands-strict-mode.yml +44 -0
  214. data/spec/spec_tests/data/versioned_api/transaction-handling.yml +180 -0
  215. data/spec/spec_tests/unified_spec.rb +15 -0
  216. data/spec/spec_tests/uri_options_spec.rb +16 -0
  217. data/spec/spec_tests/versioned_api_spec.rb +10 -0
  218. data/spec/support/client_registry.rb +4 -8
  219. data/spec/support/client_registry_macros.rb +4 -4
  220. data/spec/support/common_shortcuts.rb +15 -1
  221. data/spec/support/shared/session.rb +2 -2
  222. data/spec/support/spec_config.rb +42 -11
  223. data/spec/support/utils.rb +64 -3
  224. data.tar.gz.sig +0 -0
  225. metadata +1005 -915
  226. metadata.gz.sig +0 -0
  227. data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +0 -58
  228. data/lib/mongo/operation/shared/op_msg_or_list_indexes_command.rb +0 -47
  229. data/spec/integration/secondary_reads_spec.rb +0 -102
  230. data/spec/support/cluster_config.rb +0 -207
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Insert do
4
4
  require_no_multi_shard
5
+ require_no_required_api_version
6
+
7
+ let(:context) { Mongo::Operation::Context.new }
5
8
 
6
9
  before do
7
10
  begin
@@ -100,7 +103,7 @@ describe Mongo::Operation::Insert do
100
103
 
101
104
  let(:inserted_ids) do
102
105
  authorized_primary.with_connection do |connection|
103
- op.bulk_execute(connection, client: nil).inserted_ids
106
+ op.bulk_execute(connection, context: context).inserted_ids
104
107
  end
105
108
  end
106
109
 
@@ -131,7 +134,7 @@ describe Mongo::Operation::Insert do
131
134
 
132
135
  let(:response) do
133
136
  authorized_primary.with_connection do |connection|
134
- op.bulk_execute(connection, client: nil)
137
+ op.bulk_execute(connection, context: context)
135
138
  end
136
139
  end
137
140
 
@@ -151,7 +154,7 @@ describe Mongo::Operation::Insert do
151
154
 
152
155
  let(:response) do
153
156
  authorized_primary.with_connection do |connection|
154
- op.bulk_execute(connection, client: nil)
157
+ op.bulk_execute(connection, context: context)
155
158
  end
156
159
  end
157
160
 
@@ -190,7 +193,7 @@ describe Mongo::Operation::Insert do
190
193
 
191
194
  it 'aborts after first error' do
192
195
  authorized_primary.with_connection do |connection|
193
- failing_insert.bulk_execute(connection, client: nil)
196
+ failing_insert.bulk_execute(connection, context: context)
194
197
  end
195
198
  expect(authorized_collection.find.count).to eq(1)
196
199
  end
@@ -206,7 +209,7 @@ describe Mongo::Operation::Insert do
206
209
 
207
210
  it 'aborts after first error' do
208
211
  authorized_primary.with_connection do |connection|
209
- failing_insert.bulk_execute(connection, client: nil)
212
+ failing_insert.bulk_execute(connection, context: context)
210
213
  end
211
214
  expect(authorized_collection.find.count).to eq(1)
212
215
  end
@@ -239,7 +242,7 @@ describe Mongo::Operation::Insert do
239
242
 
240
243
  it 'does not abort after first error' do
241
244
  authorized_primary.with_connection do |connection|
242
- failing_insert.bulk_execute(connection, client: nil)
245
+ failing_insert.bulk_execute(connection, context: context)
243
246
  end
244
247
  expect(authorized_collection.find.count).to eq(2)
245
248
  end
@@ -256,7 +259,7 @@ describe Mongo::Operation::Insert do
256
259
 
257
260
  it 'does not after first error' do
258
261
  authorized_primary.with_connection do |connection|
259
- failing_insert.bulk_execute(connection, client: nil)
262
+ failing_insert.bulk_execute(connection, context: context)
260
263
  end
261
264
  expect(authorized_collection.find.count).to eq(2)
262
265
  end
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Insert do
4
+ require_no_required_api_version
5
+
6
+ let(:context) { Mongo::Operation::Context.new }
4
7
 
5
8
  let(:documents) do
6
9
  [{ '_id' => 1,
@@ -83,7 +86,7 @@ describe Mongo::Operation::Insert do
83
86
  end
84
87
 
85
88
  let(:inserted_ids) do
86
- insert.execute(authorized_primary, client: nil).inserted_ids
89
+ insert.execute(authorized_primary, context: context).inserted_ids
87
90
  end
88
91
 
89
92
  let(:collection_ids) do
@@ -112,7 +115,7 @@ describe Mongo::Operation::Insert do
112
115
  context 'when the insert succeeds' do
113
116
 
114
117
  let!(:response) do
115
- insert.execute(authorized_primary, client: nil)
118
+ insert.execute(authorized_primary, context: context)
116
119
  end
117
120
 
118
121
  it 'reports the correct written count' do
@@ -144,8 +147,8 @@ describe Mongo::Operation::Insert do
144
147
 
145
148
  it 'raises an error' do
146
149
  expect {
147
- failing_insert.execute(authorized_primary, client: nil)
148
- failing_insert.execute(authorized_primary, client: nil)
150
+ failing_insert.execute(authorized_primary, context: context)
151
+ failing_insert.execute(authorized_primary, context: context)
149
152
  }.to raise_error(Mongo::Error::OperationFailure)
150
153
  end
151
154
  end
@@ -163,7 +166,7 @@ describe Mongo::Operation::Insert do
163
166
  end
164
167
 
165
168
  let!(:response) do
166
- insert.execute(authorized_primary, client: nil)
169
+ insert.execute(authorized_primary, context: context)
167
170
  end
168
171
 
169
172
  it 'reports the correct written count' do
@@ -195,8 +198,8 @@ describe Mongo::Operation::Insert do
195
198
 
196
199
  it 'raises an error' do
197
200
  expect {
198
- failing_insert.execute(authorized_primary, client: nil)
199
- failing_insert.execute(authorized_primary, client: nil)
201
+ failing_insert.execute(authorized_primary, context: context)
202
+ failing_insert.execute(authorized_primary, context: context)
200
203
  }.to raise_error(Mongo::Error::OperationFailure)
201
204
  end
202
205
  end
@@ -221,8 +224,8 @@ describe Mongo::Operation::Insert do
221
224
 
222
225
  it 'raises an error' do
223
226
  expect {
224
- failing_insert.execute(authorized_primary, client: nil)
225
- failing_insert.execute(authorized_primary, client: nil)
227
+ failing_insert.execute(authorized_primary, context: context)
228
+ failing_insert.execute(authorized_primary, context: context)
226
229
  }.to raise_error(Mongo::Error::OperationFailure)
227
230
  end
228
231
 
@@ -236,13 +239,13 @@ describe Mongo::Operation::Insert do
236
239
 
237
240
  it 'raises an error' do
238
241
  expect {
239
- insert.execute(authorized_primary, client: nil)
242
+ insert.execute(authorized_primary, context: context)
240
243
  }.to raise_error(Mongo::Error::MaxBSONSize)
241
244
  end
242
245
 
243
246
  it 'does not insert the document' do
244
247
  expect {
245
- insert.execute(authorized_primary, client: nil)
248
+ insert.execute(authorized_primary, context: context)
246
249
  }.to raise_error(Mongo::Error::MaxBSONSize)
247
250
  expect(authorized_collection.find.count).to eq(0)
248
251
  end
@@ -273,7 +276,7 @@ describe Mongo::Operation::Insert do
273
276
  end
274
277
 
275
278
  let(:response) do
276
- op.execute(authorized_primary, client: nil)
279
+ op.execute(authorized_primary, context: context)
277
280
  end
278
281
 
279
282
  it 'uses op codes instead of write commands' do
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::MapReduce do
4
+ require_no_required_api_version
5
+
6
+ let(:context) { Mongo::Operation::Context.new }
4
7
 
5
8
  let(:map) do
6
9
  %Q{
@@ -97,7 +100,7 @@ describe Mongo::Operation::MapReduce do
97
100
  context 'when the map/reduce succeeds' do
98
101
 
99
102
  let(:response) do
100
- op.execute(authorized_primary, client: nil)
103
+ op.execute(authorized_primary, context: context)
101
104
  end
102
105
 
103
106
  it 'returns the response' do
@@ -117,7 +120,7 @@ describe Mongo::Operation::MapReduce do
117
120
 
118
121
  it 'raises an exception' do
119
122
  expect {
120
- op.execute(authorized_primary, client: nil)
123
+ op.execute(authorized_primary, context: context)
121
124
  }.to raise_error(Mongo::Error::OperationFailure)
122
125
  end
123
126
  end
@@ -46,10 +46,10 @@ describe Mongo::Operation::ReadPreferenceSupported do
46
46
  end
47
47
  end
48
48
 
49
- describe '#add_slave_ok_flag?' do
49
+ describe '#add_slave_ok_flag_maybe' do
50
50
 
51
51
  let(:actual) do
52
- operation.send(:add_slave_ok_flag?, connection)
52
+ operation.send(:add_slave_ok_flag_maybe, operation.send(:options), connection)
53
53
  end
54
54
 
55
55
  shared_examples_for 'sets the slave_ok flag as expected' do
@@ -60,7 +60,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
60
60
 
61
61
  shared_examples_for 'never sets slave_ok' do
62
62
 
63
- let(:expected) { false }
63
+ let(:expected) do
64
+ { }
65
+ end
64
66
 
65
67
  context 'when no read preference is specified' do
66
68
  let(:read_pref) { Mongo::ServerSelector.get }
@@ -83,7 +85,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
83
85
 
84
86
  shared_examples_for 'always sets slave_ok' do
85
87
 
86
- let(:expected) { true }
88
+ let(:expected) do
89
+ { :flags => [ :slave_ok ] }
90
+ end
87
91
 
88
92
  context 'when no read preference is specified' do
89
93
  let(:read_pref) { Mongo::ServerSelector.get }
@@ -110,7 +114,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
110
114
 
111
115
  let(:read_pref) { Mongo::ServerSelector.get }
112
116
 
113
- let(:expected) { false }
117
+ let(:expected) do
118
+ { }
119
+ end
114
120
 
115
121
  it_behaves_like 'sets the slave_ok flag as expected'
116
122
  end
@@ -121,7 +127,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
121
127
 
122
128
  let(:read_pref) { Mongo::ServerSelector.get(:mode => :secondary) }
123
129
 
124
- let(:expected) { true }
130
+ let(:expected) do
131
+ { :flags => [ :slave_ok ] }
132
+ end
125
133
 
126
134
  it_behaves_like 'sets the slave_ok flag as expected'
127
135
  end
@@ -130,7 +138,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
130
138
 
131
139
  let(:read_pref) { Mongo::ServerSelector.get(:mode => :primary) }
132
140
 
133
- let(:expected) { false }
141
+ let(:expected) do
142
+ { }
143
+ end
134
144
 
135
145
  it_behaves_like 'sets the slave_ok flag as expected'
136
146
  end
@@ -196,7 +206,7 @@ describe Mongo::Operation::ReadPreferenceSupported do
196
206
  end
197
207
  end
198
208
 
199
- describe '#add_read_preference_legacy' do
209
+ describe '#update_selector_for_read_pref' do
200
210
 
201
211
  let(:read_pref) do
202
212
  Mongo::ServerSelector.get(:mode => mode)
@@ -205,7 +215,7 @@ describe Mongo::Operation::ReadPreferenceSupported do
205
215
  # Behavior of sending $readPreference is the same regardless of topology.
206
216
  shared_examples_for '$readPreference in the command' do
207
217
  let(:actual) do
208
- operation.send(:add_read_preference_legacy, operation.send(:selector), connection)
218
+ operation.send(:update_selector_for_read_pref, operation.send(:selector), connection)
209
219
  end
210
220
 
211
221
  let(:expected_read_preference) do
@@ -175,13 +175,13 @@ describe Mongo::Operation::SessionsSupported do
175
175
  let(:tag_sets) { nil }
176
176
 
177
177
  context 'without tag_sets specified' do
178
- it_behaves_like 'adds read preference'
178
+ it_behaves_like 'does not modify selector'
179
179
  end
180
180
 
181
181
  context 'with empty tag_sets' do
182
182
  let(:tag_sets) { [] }
183
183
 
184
- it_behaves_like 'adds read preference'
184
+ it_behaves_like 'does not modify selector'
185
185
  end
186
186
 
187
187
  context 'with tag_sets specified' do
@@ -256,7 +256,7 @@ describe Mongo::Operation::SessionsSupported do
256
256
  let(:hedge) { nil }
257
257
 
258
258
  context 'when tag_sets and hedge are not specified' do
259
- it_behaves_like 'adds read preference'
259
+ it_behaves_like 'does not modify selector'
260
260
  end
261
261
 
262
262
  context 'when tag_sets are specified' do
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::RemoveUser do
4
+ require_no_required_api_version
5
+
6
+ let(:context) { Mongo::Operation::Context.new }
4
7
 
5
8
  describe '#execute' do
6
9
 
@@ -22,7 +25,7 @@ describe Mongo::Operation::RemoveUser do
22
25
  context 'when user removal was successful' do
23
26
 
24
27
  let!(:response) do
25
- operation.execute(root_authorized_primary, client: nil)
28
+ operation.execute(root_authorized_primary, context: context)
26
29
  end
27
30
 
28
31
  it 'removes the user from the database' do
@@ -33,12 +36,12 @@ describe Mongo::Operation::RemoveUser do
33
36
  context 'when removal was not successful' do
34
37
 
35
38
  before do
36
- operation.execute(root_authorized_primary, client: nil)
39
+ operation.execute(root_authorized_primary, context: context)
37
40
  end
38
41
 
39
42
  it 'raises an exception' do
40
43
  expect {
41
- operation.execute(root_authorized_primary, client: nil)
44
+ operation.execute(root_authorized_primary, context: context)
42
45
  }.to raise_error(Mongo::Error::OperationFailure)
43
46
  end
44
47
  end
@@ -337,7 +337,7 @@ describe Mongo::Operation::Result do
337
337
  it 'raises OperationFailure' do
338
338
  expect do
339
339
  result.validate!
340
- end.to raise_error(Mongo::Error::OperationFailure, /Replication is being shut down \(91\)/)
340
+ end.to raise_error(Mongo::Error::OperationFailure, /\[91\]: Replication is being shut down/)
341
341
  end
342
342
  end
343
343
  end
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Update do
4
4
  require_no_multi_shard
5
+ require_no_required_api_version
6
+
7
+ let(:context) { Mongo::Operation::Context.new }
5
8
 
6
9
  let(:documents) do
7
10
  [{ :q => { :foo => 1 },
@@ -99,7 +102,7 @@ describe Mongo::Operation::Update do
99
102
 
100
103
  it 'updates the document' do
101
104
  authorized_primary.with_connection do |connection|
102
- op.bulk_execute(connection, client: nil)
105
+ op.bulk_execute(connection, context: context)
103
106
  end
104
107
  expect(authorized_collection.find(field: 'blah').count).to eq(1)
105
108
  end
@@ -125,7 +128,7 @@ describe Mongo::Operation::Update do
125
128
 
126
129
  it 'updates the documents' do
127
130
  authorized_primary.with_connection do |connection|
128
- op.bulk_execute(connection, client: nil)
131
+ op.bulk_execute(connection, context: context)
129
132
  end
130
133
  expect(authorized_collection.find(field: 'blah').count).to eq(2)
131
134
  end
@@ -159,7 +162,7 @@ describe Mongo::Operation::Update do
159
162
 
160
163
  it 'aborts after first error' do
161
164
  authorized_primary.with_connection do |connection|
162
- failing_update.bulk_execute(connection, client: nil)
165
+ failing_update.bulk_execute(connection, context: context)
163
166
  end
164
167
  expect(authorized_collection.find(other: 'blah').count).to eq(0)
165
168
  end
@@ -173,7 +176,7 @@ describe Mongo::Operation::Update do
173
176
 
174
177
  it 'aborts after first error' do
175
178
  authorized_primary.with_connection do |connection|
176
- failing_update.bulk_execute(connection, client: nil)
179
+ failing_update.bulk_execute(connection, context: context)
177
180
  end
178
181
  expect(authorized_collection.find(other: 'blah').count).to eq(0)
179
182
  end
@@ -208,7 +211,7 @@ describe Mongo::Operation::Update do
208
211
 
209
212
  it 'does not abort after first error' do
210
213
  authorized_primary.with_connection do |connection|
211
- failing_update.bulk_execute(connection, client: nil)
214
+ failing_update.bulk_execute(connection, context: context)
212
215
  end
213
216
  expect(authorized_collection.find(other: 'blah').count).to eq(1)
214
217
  end
@@ -222,7 +225,7 @@ describe Mongo::Operation::Update do
222
225
 
223
226
  it 'does not abort after first error' do
224
227
  authorized_primary.with_connection do |connection|
225
- failing_update.bulk_execute(connection, client: nil)
228
+ failing_update.bulk_execute(connection, context: context)
226
229
  end
227
230
  expect(authorized_collection.find(other: 'blah').count).to eq(1)
228
231
  end
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Update do
4
+ require_no_required_api_version
5
+
6
+ let(:context) { Mongo::Operation::Context.new }
4
7
 
5
8
  let(:document) do
6
9
  { :q => { :foo => 1 },
@@ -100,7 +103,7 @@ describe Mongo::Operation::Update do
100
103
  end
101
104
 
102
105
  let(:result) do
103
- update.execute(authorized_primary, client: nil)
106
+ update.execute(authorized_primary, context: context)
104
107
  end
105
108
 
106
109
  it 'updates the document' do
@@ -128,7 +131,7 @@ describe Mongo::Operation::Update do
128
131
 
129
132
  it 'raises an exception' do
130
133
  expect {
131
- update.execute(authorized_primary, client: nil)
134
+ update.execute(authorized_primary, context: context)
132
135
  }.to raise_error(Mongo::Error::OperationFailure)
133
136
  end
134
137
  end
@@ -152,7 +155,7 @@ describe Mongo::Operation::Update do
152
155
  end
153
156
 
154
157
  let(:result) do
155
- update.execute(authorized_primary, client: nil)
158
+ update.execute(authorized_primary, context: context)
156
159
  end
157
160
 
158
161
  it 'updates the documents' do
@@ -180,7 +183,7 @@ describe Mongo::Operation::Update do
180
183
 
181
184
  it 'raises an exception' do
182
185
  expect {
183
- update.execute(authorized_primary, client: nil)
186
+ update.execute(authorized_primary, context: context)
184
187
  }.to raise_error(Mongo::Error::OperationFailure)
185
188
  end
186
189
  end
@@ -193,7 +196,7 @@ describe Mongo::Operation::Update do
193
196
 
194
197
  it 'raises an error' do
195
198
  expect {
196
- update.execute(authorized_primary, client: nil)
199
+ update.execute(authorized_primary, context: context)
197
200
  }.to raise_error(Mongo::Error::MaxBSONSize)
198
201
  end
199
202
  end
@@ -205,7 +208,7 @@ describe Mongo::Operation::Update do
205
208
  end
206
209
 
207
210
  let(:result) do
208
- update.execute(authorized_primary, client: nil)
211
+ update.execute(authorized_primary, context: context)
209
212
  end
210
213
 
211
214
  it 'inserts the document' do
@@ -243,7 +246,7 @@ describe Mongo::Operation::Update do
243
246
  end
244
247
 
245
248
  let(:result) do
246
- update.execute(authorized_primary, client: nil)
249
+ update.execute(authorized_primary, context: context)
247
250
  end
248
251
 
249
252
  before do
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::UpdateUser do
4
+ require_no_required_api_version
5
+
6
+ let(:context) { Mongo::Operation::Context.new }
4
7
 
5
8
  describe '#execute' do
6
9
 
@@ -35,7 +38,7 @@ describe Mongo::Operation::UpdateUser do
35
38
  context 'when user update was successful' do
36
39
 
37
40
  let!(:response) do
38
- operation.execute(root_authorized_primary, client: nil)
41
+ operation.execute(root_authorized_primary, context: context)
39
42
  end
40
43
 
41
44
  it 'updates the user in the database' do
@@ -1,4 +1,4 @@
1
- require 'lite_spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Mongo::Protocol::Compressed do
4
4
 
@@ -10,15 +10,35 @@ describe Mongo::Protocol::Compressed do
10
10
  described_class.new(original_message, compressor, level)
11
11
  end
12
12
 
13
+ let(:original_message_bytes) do
14
+ buf = BSON::ByteBuffer.new
15
+ original_message.send(:serialize_fields, buf)
16
+ buf.to_s
17
+ end
18
+
13
19
  describe '#serialize' do
14
20
 
15
- context 'when zlib compression level is not provided' do
21
+ context "when using the snappy compressor" do
22
+ require_snappy_compression
23
+ let(:compressor) { 'snappy' }
24
+
25
+ it "uses snappy" do
26
+ expect(Snappy).to receive(:deflate).with(original_message_bytes).and_call_original
27
+ message.serialize
28
+ end
29
+ end
16
30
 
17
- let(:original_message_bytes) do
18
- buf = BSON::ByteBuffer.new
19
- original_message.send(:serialize_fields, buf)
20
- buf.to_s
31
+ context "when using the zstd compressor" do
32
+ require_zstd_compression
33
+ let(:compressor) { 'zstd' }
34
+
35
+ it "uses zstd with default compression level" do
36
+ expect(Zstd).to receive(:compress).with(original_message_bytes).and_call_original
37
+ message.serialize
21
38
  end
39
+ end
40
+
41
+ context 'when zlib compression level is not provided' do
22
42
 
23
43
  it 'does not set a compression level' do
24
44
  expect(Zlib::Deflate).to receive(:deflate).with(original_message_bytes, nil).and_call_original
@@ -30,12 +50,6 @@ describe Mongo::Protocol::Compressed do
30
50
 
31
51
  let(:level) { 1 }
32
52
 
33
- let(:original_message_bytes) do
34
- buf = BSON::ByteBuffer.new
35
- original_message.send(:serialize_fields, buf)
36
- buf.to_s
37
- end
38
-
39
53
  it 'uses the compression level' do
40
54
  expect(Zlib::Deflate).to receive(:deflate).with(original_message_bytes, 1).and_call_original
41
55
  message.serialize
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require "spec_helper"
5
+
6
+ describe Mongo::QueryCache::Middleware do
7
+
8
+ let :middleware do
9
+ described_class.new(app)
10
+ end
11
+
12
+ context "when not touching query cache in the app" do
13
+
14
+ let(:app) do
15
+ lambda do |env|
16
+ @enabled = Mongo::QueryCache.enabled?
17
+ [200, env, "app"]
18
+ end
19
+ end
20
+
21
+ it "returns success" do
22
+ code, _ = middleware.call({})
23
+ expect(code).to eq(200)
24
+ end
25
+
26
+ it "enables the query cache" do
27
+ middleware.call({})
28
+ expect(@enabled).to be true
29
+ end
30
+ end
31
+
32
+ context "when querying in the app" do
33
+
34
+ before do
35
+ authorized_client['test'].insert_one(test: 1)
36
+ end
37
+
38
+ let(:app) do
39
+ lambda do |env|
40
+ authorized_client['test'].find
41
+ [200, env, "app"]
42
+ end
43
+ end
44
+
45
+ it "returns success" do
46
+ code, _ = middleware.call({})
47
+ expect(code).to eq(200)
48
+ end
49
+
50
+ it "cleans the query cache after it responds" do
51
+ middleware.call({})
52
+ expect(Mongo::QueryCache.send(:cache_table)).to be_empty
53
+ end
54
+ end
55
+ end
@@ -574,8 +574,9 @@ describe Mongo::Retryable do
574
574
  context 'when an error due to using an unsupported storage engine occurs' do
575
575
  before do
576
576
  expect(operation).to receive(:execute).and_raise(
577
- Mongo::Error::OperationFailure.new('Transaction numbers are only allowed on...',
578
- nil, :code=>20)).ordered
577
+ Mongo::Error::OperationFailure.new('message which is not checked',
578
+ nil, code: 20, server_message: 'Transaction numbers are only allowed on...',
579
+ )).ordered
579
580
  end
580
581
 
581
582
  it 'raises an exception with the correct error message' do
@@ -8,40 +8,14 @@ shared_examples 'app metadata document' do
8
8
  document[:client][:driver][:version].should == Mongo::VERSION
9
9
  end
10
10
 
11
- context 'linux' do
12
- before(:all) do
13
- unless SpecConfig.instance.linux?
14
- skip "Linux required, we have #{RbConfig::CONFIG['host_os']}"
15
- end
16
- end
17
-
18
- it 'includes operating system information' do
19
- document[:client][:os][:type].should == 'linux'
20
- if BSON::Environment.jruby? || RUBY_VERSION >= '3.0'
21
- document[:client][:os][:name].should == 'linux'
22
- else
23
- document[:client][:os][:name].should == 'linux-gnu'
24
- end
25
- document[:client][:os][:architecture].should == 'x86_64'
26
- end
27
- end
28
-
29
- context 'macos' do
30
- before(:all) do
31
- unless SpecConfig.instance.macos?
32
- skip "MacOS required, we have #{RbConfig::CONFIG['host_os']}"
33
- end
34
- end
35
-
36
- it 'includes operating system information' do
37
- document[:client][:os][:type].should == 'darwin'
38
- if BSON::Environment.jruby?
39
- document[:client][:os][:name].should == 'darwin'
40
- else
41
- document[:client][:os][:name].should =~ /darwin\d+/
42
- end
43
- document[:client][:os][:architecture].should == 'x86_64'
11
+ it 'includes operating system information' do
12
+ document[:client][:os][:type].should == 'linux'
13
+ if BSON::Environment.jruby? || RUBY_VERSION >= '3.0'
14
+ document[:client][:os][:name].should == 'linux'
15
+ else
16
+ document[:client][:os][:name].should == 'linux-gnu'
44
17
  end
18
+ document[:client][:os][:architecture].should == 'x86_64'
45
19
  end
46
20
 
47
21
  context 'mri' do