mongo 2.13.2 → 2.14.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) 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 +9 -0
  5. data/lib/mongo/address.rb +1 -1
  6. data/lib/mongo/address/ipv4.rb +1 -1
  7. data/lib/mongo/address/ipv6.rb +1 -1
  8. data/lib/mongo/bulk_write.rb +17 -0
  9. data/lib/mongo/caching_cursor.rb +74 -0
  10. data/lib/mongo/client.rb +47 -8
  11. data/lib/mongo/cluster.rb +3 -3
  12. data/lib/mongo/cluster/topology/single.rb +1 -1
  13. data/lib/mongo/collection.rb +26 -0
  14. data/lib/mongo/collection/view.rb +24 -20
  15. data/lib/mongo/collection/view/aggregation.rb +25 -4
  16. data/lib/mongo/collection/view/builder/find_command.rb +38 -18
  17. data/lib/mongo/collection/view/explainable.rb +27 -8
  18. data/lib/mongo/collection/view/iterable.rb +72 -12
  19. data/lib/mongo/collection/view/readable.rb +12 -2
  20. data/lib/mongo/collection/view/writable.rb +15 -1
  21. data/lib/mongo/crypt/encryption_io.rb +6 -6
  22. data/lib/mongo/cursor.rb +1 -0
  23. data/lib/mongo/database.rb +6 -0
  24. data/lib/mongo/database/view.rb +1 -1
  25. data/lib/mongo/error.rb +2 -0
  26. data/lib/mongo/error/invalid_read_concern.rb +28 -0
  27. data/lib/mongo/error/server_certificate_revoked.rb +22 -0
  28. data/lib/mongo/error/unsupported_option.rb +14 -12
  29. data/lib/mongo/lint.rb +2 -1
  30. data/lib/mongo/logger.rb +3 -3
  31. data/lib/mongo/operation.rb +2 -0
  32. data/lib/mongo/operation/aggregate/result.rb +9 -8
  33. data/lib/mongo/operation/collections_info/command.rb +0 -5
  34. data/lib/mongo/operation/collections_info/result.rb +3 -16
  35. data/lib/mongo/operation/delete/bulk_result.rb +2 -0
  36. data/lib/mongo/operation/delete/result.rb +3 -0
  37. data/lib/mongo/operation/explain/command.rb +4 -0
  38. data/lib/mongo/operation/explain/legacy.rb +4 -0
  39. data/lib/mongo/operation/explain/op_msg.rb +6 -0
  40. data/lib/mongo/operation/explain/result.rb +3 -0
  41. data/lib/mongo/operation/find/legacy/result.rb +2 -0
  42. data/lib/mongo/operation/find/result.rb +3 -0
  43. data/lib/mongo/operation/get_more/result.rb +3 -0
  44. data/lib/mongo/operation/indexes/result.rb +5 -0
  45. data/lib/mongo/operation/insert/bulk_result.rb +5 -0
  46. data/lib/mongo/operation/insert/result.rb +5 -0
  47. data/lib/mongo/operation/list_collections/result.rb +5 -0
  48. data/lib/mongo/operation/map_reduce/result.rb +10 -0
  49. data/lib/mongo/operation/parallel_scan/result.rb +4 -0
  50. data/lib/mongo/operation/result.rb +35 -6
  51. data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
  52. data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
  53. data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
  54. data/lib/mongo/operation/shared/executable.rb +1 -0
  55. data/lib/mongo/operation/shared/idable.rb +2 -1
  56. data/lib/mongo/operation/shared/limited.rb +1 -0
  57. data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
  58. data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
  59. data/lib/mongo/operation/shared/sessions_supported.rb +1 -0
  60. data/lib/mongo/operation/shared/specifiable.rb +1 -0
  61. data/lib/mongo/operation/shared/write.rb +1 -0
  62. data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
  63. data/lib/mongo/operation/update/legacy/result.rb +7 -0
  64. data/lib/mongo/operation/update/result.rb +8 -0
  65. data/lib/mongo/operation/users_info/result.rb +3 -0
  66. data/lib/mongo/query_cache.rb +242 -0
  67. data/lib/mongo/retryable.rb +8 -1
  68. data/lib/mongo/server.rb +5 -1
  69. data/lib/mongo/server/connection_common.rb +2 -2
  70. data/lib/mongo/server/connection_pool.rb +3 -0
  71. data/lib/mongo/server/monitor.rb +1 -1
  72. data/lib/mongo/server/monitor/connection.rb +3 -3
  73. data/lib/mongo/server/pending_connection.rb +2 -2
  74. data/lib/mongo/server/push_monitor.rb +1 -1
  75. data/lib/mongo/server_selector/base.rb +5 -1
  76. data/lib/mongo/session.rb +3 -0
  77. data/lib/mongo/socket.rb +6 -4
  78. data/lib/mongo/socket/ocsp_cache.rb +97 -0
  79. data/lib/mongo/socket/ocsp_verifier.rb +368 -0
  80. data/lib/mongo/socket/ssl.rb +45 -24
  81. data/lib/mongo/srv/monitor.rb +7 -13
  82. data/lib/mongo/srv/resolver.rb +14 -10
  83. data/lib/mongo/timeout.rb +2 -0
  84. data/lib/mongo/uri.rb +21 -390
  85. data/lib/mongo/uri/options_mapper.rb +582 -0
  86. data/lib/mongo/uri/srv_protocol.rb +3 -2
  87. data/lib/mongo/utils.rb +12 -1
  88. data/lib/mongo/version.rb +1 -1
  89. data/spec/NOTES.aws-auth.md +12 -7
  90. data/spec/README.md +56 -1
  91. data/spec/integration/bson_symbol_spec.rb +2 -4
  92. data/spec/integration/bulk_write_spec.rb +48 -0
  93. data/spec/integration/client_authentication_options_spec.rb +55 -28
  94. data/spec/integration/connection_pool_populator_spec.rb +3 -1
  95. data/spec/integration/cursor_reaping_spec.rb +53 -17
  96. data/spec/integration/ocsp_connectivity_spec.rb +26 -0
  97. data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
  98. data/spec/integration/ocsp_verifier_spec.rb +334 -0
  99. data/spec/integration/query_cache_spec.rb +1045 -0
  100. data/spec/integration/query_cache_transactions_spec.rb +179 -0
  101. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
  102. data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
  103. data/spec/integration/sdam_error_handling_spec.rb +68 -17
  104. data/spec/integration/sdam_events_spec.rb +5 -8
  105. data/spec/integration/server_selection_spec.rb +36 -0
  106. data/spec/integration/srv_monitoring_spec.rb +38 -3
  107. data/spec/integration/srv_spec.rb +56 -0
  108. data/spec/lite_spec_helper.rb +4 -2
  109. data/spec/mongo/address_spec.rb +1 -1
  110. data/spec/mongo/caching_cursor_spec.rb +70 -0
  111. data/spec/mongo/client_construction_spec.rb +54 -1
  112. data/spec/mongo/client_encryption_spec.rb +10 -16
  113. data/spec/mongo/client_spec.rb +40 -0
  114. data/spec/mongo/cluster/topology/single_spec.rb +14 -5
  115. data/spec/mongo/cluster_spec.rb +3 -0
  116. data/spec/mongo/collection/view/explainable_spec.rb +87 -4
  117. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
  118. data/spec/mongo/collection_spec.rb +60 -0
  119. data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
  120. data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
  121. data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
  122. data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
  123. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
  124. data/spec/mongo/database_spec.rb +44 -64
  125. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  126. data/spec/mongo/logger_spec.rb +13 -11
  127. data/spec/mongo/query_cache_spec.rb +279 -0
  128. data/spec/mongo/server/app_metadata_shared.rb +1 -1
  129. data/spec/mongo/server/connection_pool_spec.rb +7 -3
  130. data/spec/mongo/server/connection_spec.rb +14 -7
  131. data/spec/mongo/socket/ssl_spec.rb +1 -1
  132. data/spec/mongo/socket_spec.rb +1 -1
  133. data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
  134. data/spec/mongo/uri_option_parsing_spec.rb +11 -11
  135. data/spec/mongo/uri_spec.rb +68 -41
  136. data/spec/mongo/utils_spec.rb +39 -0
  137. data/spec/runners/auth.rb +3 -0
  138. data/spec/runners/connection_string.rb +35 -124
  139. data/spec/spec_tests/cmap_spec.rb +7 -3
  140. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
  141. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
  142. data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
  143. data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
  144. data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
  145. data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
  146. data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
  147. data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
  148. data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
  149. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
  150. data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
  151. data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
  152. data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
  153. data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
  154. data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
  155. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
  156. data/spec/spec_tests/uri_options_spec.rb +31 -33
  157. data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
  158. data/spec/support/certificates/atlas-ocsp.crt +41 -0
  159. data/spec/support/client_registry_macros.rb +11 -2
  160. data/spec/support/common_shortcuts.rb +45 -0
  161. data/spec/support/constraints.rb +23 -0
  162. data/spec/support/lite_constraints.rb +24 -0
  163. data/spec/support/matchers.rb +16 -0
  164. data/spec/support/ocsp +1 -0
  165. data/spec/support/session_registry.rb +52 -0
  166. data/spec/support/spec_config.rb +22 -0
  167. data/spec/support/utils.rb +19 -1
  168. metadata +1017 -992
  169. metadata.gz.sig +0 -0
  170. data/spec/shared/LICENSE +0 -20
  171. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  172. data/spec/shared/lib/mrss/constraints.rb +0 -303
  173. data/spec/shared/lib/mrss/lite_constraints.rb +0 -175
  174. data/spec/shared/lib/mrss/spec_organizer.rb +0 -149
@@ -49,6 +49,7 @@ end
49
49
  autoload :Benchmark, 'benchmark'
50
50
  autoload :IceNine, 'ice_nine'
51
51
  autoload :Timecop, 'timecop'
52
+ autoload :ChildProcess, 'childprocess'
52
53
 
53
54
  if BSON::Environment.jruby?
54
55
  require 'concurrent-ruby'
@@ -60,7 +61,7 @@ end
60
61
  require 'support/utils'
61
62
  require 'support/spec_config'
62
63
 
63
- Mongo::Logger.logger = Logger.new($stdout)
64
+ Mongo::Logger.logger = Logger.new(STDOUT)
64
65
  unless SpecConfig.instance.client_debug?
65
66
  Mongo::Logger.logger.level = Logger::INFO
66
67
  end
@@ -76,6 +77,7 @@ require 'support/crypt'
76
77
  require 'support/json_ext_formatter'
77
78
  require 'support/sdam_formatter_integration'
78
79
  require 'support/background_thread_registry'
80
+ require 'support/session_registry'
79
81
 
80
82
  if SpecConfig.instance.mri?
81
83
  require 'timeout_interrupt'
@@ -104,7 +106,7 @@ RSpec.configure do |config|
104
106
  end
105
107
  end
106
108
 
107
- if SpecConfig.instance.ci? && !%w(1 true yes).include?(ENV['INTERACTIVE']&.downcase)
109
+ if SpecConfig.instance.ci?
108
110
  # Allow a max of 30 seconds per test.
109
111
  # Tests should take under 10 seconds ideally but it seems
110
112
  # we have some that run for more than 10 seconds in CI.
@@ -234,7 +234,7 @@ describe Mongo::Address do
234
234
  end
235
235
 
236
236
  let(:address) do
237
- Mongo::Address.new(custom_hostname)
237
+ Mongo::Address.new("#{custom_hostname}:#{SpecConfig.instance.any_port}")
238
238
  end
239
239
 
240
240
  before do
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongo::CachingCursor do
4
+
5
+ around do |spec|
6
+ Mongo::QueryCache.clear
7
+ Mongo::QueryCache.cache { spec.run }
8
+ end
9
+
10
+ let(:authorized_collection) do
11
+ authorized_client['caching_cursor']
12
+ end
13
+
14
+ before do
15
+ authorized_collection.drop
16
+ end
17
+
18
+ let(:server) do
19
+ view.send(:server_selector).select_server(authorized_client.cluster)
20
+ end
21
+
22
+ let(:reply) do
23
+ view.send(:send_initial_query, server)
24
+ end
25
+
26
+ let(:cursor) do
27
+ described_class.new(view, reply, server)
28
+ end
29
+
30
+ let(:view) do
31
+ Mongo::Collection::View.new(authorized_collection)
32
+ end
33
+
34
+ before do
35
+ authorized_collection.delete_many
36
+ 3.times { |i| authorized_collection.insert_one(_id: i) }
37
+ end
38
+
39
+ describe '#cached_docs' do
40
+ context 'when no query has been performed' do
41
+ it 'returns nil' do
42
+ expect(cursor.cached_docs).to be_nil
43
+ end
44
+ end
45
+
46
+ context 'when a query has been performed' do
47
+ it 'returns the number of documents' do
48
+ cursor.to_a
49
+ expect(cursor.cached_docs.length).to eq(3)
50
+ expect(cursor.cached_docs).to eq([{ '_id' => 0 }, { '_id' => 1 }, { '_id' => 2 }])
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#try_next' do
56
+ it 'fetches the next document' do
57
+ expect(cursor.try_next).to eq('_id' => 0)
58
+ expect(cursor.try_next).to eq('_id' => 1)
59
+ expect(cursor.try_next).to eq('_id' => 2)
60
+ end
61
+ end
62
+
63
+ describe '#each' do
64
+ it 'iterates the cursor' do
65
+ result = cursor.each.to_a
66
+ expect(result.length).to eq(3)
67
+ expect(result).to eq([{ '_id' => 0 }, { '_id' => 1 }, { '_id' => 2 }])
68
+ end
69
+ end
70
+ end
@@ -496,6 +496,7 @@ describe Mongo::Client do
496
496
  end
497
497
 
498
498
  context 'when the compressor is not supported by the driver' do
499
+ require_warning_clean
499
500
 
500
501
  let(:options) do
501
502
  { compressors: ['snoopy'] }
@@ -674,7 +675,7 @@ describe Mongo::Client do
674
675
  context 'when providing a custom logger' do
675
676
 
676
677
  let(:logger) do
677
- Logger.new($stdout).tap do |l|
678
+ Logger.new(STDOUT).tap do |l|
678
679
  l.level = Logger::FATAL
679
680
  end
680
681
  end
@@ -1343,6 +1344,46 @@ describe Mongo::Client do
1343
1344
  end
1344
1345
  end
1345
1346
 
1347
+ context 'when setting read concern options' do
1348
+ min_server_fcv '3.2'
1349
+
1350
+ context 'when read concern is valid' do
1351
+ let(:options) do
1352
+ { read_concern: { level: :local } }
1353
+ end
1354
+
1355
+ it 'does not warn' do
1356
+ expect(Mongo::Logger.logger).to_not receive(:warn)
1357
+ new_local_client_nmio(SpecConfig.instance.addresses, options)
1358
+ end
1359
+ end
1360
+
1361
+ context 'when read concern has an invalid key' do
1362
+ skip_if_linting
1363
+
1364
+ let(:options) do
1365
+ { read_concern: { hello: :local } }
1366
+ end
1367
+
1368
+ it 'logs a warning' do
1369
+ expect(Mongo::Logger.logger).to receive(:warn).with(/Read concern has invalid keys: hello/)
1370
+ new_local_client_nmio(SpecConfig.instance.addresses, options)
1371
+ end
1372
+ end
1373
+
1374
+ context 'when read concern has a non-user-settable key' do
1375
+ let(:options) do
1376
+ { read_concern: { after_cluster_time: 100 } }
1377
+ end
1378
+
1379
+ it 'raises an exception' do
1380
+ expect do
1381
+ new_local_client_nmio(SpecConfig.instance.addresses, options)
1382
+ end.to raise_error(Mongo::Error::InvalidReadConcern, 'The after_cluster_time read_concern option cannot be specified by the user')
1383
+ end
1384
+ end
1385
+ end
1386
+
1346
1387
  context 'when an invalid option is provided' do
1347
1388
 
1348
1389
  let(:options) do
@@ -1494,6 +1535,18 @@ describe Mongo::Client do
1494
1535
  end
1495
1536
  end
1496
1537
  end
1538
+
1539
+ context ':auth_mech_properties option' do
1540
+ context 'is nil' do
1541
+ let(:options) do
1542
+ {auth_mech_properties: nil}
1543
+ end
1544
+
1545
+ it 'creates the client without the option' do
1546
+ client.options.should_not have_key(:auth_mech_properties)
1547
+ end
1548
+ end
1549
+ end
1497
1550
  end
1498
1551
 
1499
1552
  context 'when making a block client' do
@@ -268,7 +268,7 @@ describe Mongo::ClientEncryption do
268
268
  it_behaves_like 'it creates a data key'
269
269
  end
270
270
 
271
- context 'with https' do
271
+ context 'with invalid endpoint' do
272
272
  let(:options) do
273
273
  {
274
274
  master_key: {
@@ -279,26 +279,20 @@ describe Mongo::ClientEncryption do
279
279
  }
280
280
  end
281
281
 
282
- it_behaves_like 'it creates a data key'
283
- end
284
-
285
- context 'with invalid endpoint' do
286
- let(:options) do
287
- {
288
- master_key: {
289
- key: aws_arn,
290
- region: aws_region,
291
- endpoint: "invalid-nonsense-endpoint.com"
292
- }
293
- }
282
+ let(:expected_message) do
283
+ # RUBY-2129: This error message could be more specific and inform the user
284
+ # that there is a problem with their KMS endpoint
285
+ if BSON::Environment.jruby?
286
+ /getservbyname.* failed/
287
+ else
288
+ /SocketError/
289
+ end
294
290
  end
295
291
 
296
292
  it 'raises an exception' do
297
- # RUBY-2129: This error message could be more specific and inform the user
298
- # that there is a problem with their KMS endpoint
299
293
  expect do
300
294
  data_key_id
301
- end.to raise_error(Mongo::Error::KmsError, /SocketError/)
295
+ end.to raise_error(Mongo::Error::KmsError, expected_message)
302
296
  end
303
297
  end
304
298
 
@@ -894,4 +894,44 @@ describe Mongo::Client do
894
894
  end
895
895
  end
896
896
  end
897
+
898
+ describe '#summary' do
899
+
900
+ context 'monitoring omitted' do
901
+ let(:client) do
902
+ new_local_client_nmio(
903
+ ['127.0.0.1:27017'],
904
+ :read => { :mode => :primary },
905
+ :database => SpecConfig.instance.test_db
906
+ )
907
+ end
908
+
909
+ it 'indicates lack of monitoring' do
910
+ client.summary.should =~ /servers=.*UNKNOWN.*NO-MONITORING/
911
+ end
912
+ end
913
+
914
+ context 'monitoring present' do
915
+ let(:client) do
916
+ authorized_client
917
+ end
918
+
919
+ it 'does not indicate lack of monitoring' do
920
+ client.summary.should =~ /servers=.*(STANDALONE|PRIMARY|MONGOS)/
921
+ client.summary.should_not =~ /servers=.*(STANDALONE|PRIMARY|MONGOS).*NO-MONITORING/
922
+ end
923
+ end
924
+
925
+ context 'background threads killed' do
926
+ let(:client) do
927
+ authorized_client.tap do |client|
928
+ client.cluster.servers.map(&:disconnect!)
929
+ end
930
+ end
931
+
932
+ it 'does not indicate lack of monitoring' do
933
+ client.summary.should =~ /servers=.*(STANDALONE|PRIMARY|MONGOS).*NO-MONITORING/
934
+ end
935
+ end
936
+ end
897
937
  end
@@ -113,19 +113,28 @@ describe Mongo::Cluster::Topology::Single do
113
113
  monitoring, temp_cluster)
114
114
  end
115
115
 
116
+ let(:server_1) do
117
+ double('server').tap do |server|
118
+ allow(server).to receive(:address).and_return(Mongo::Address.new('one'))
119
+ end
120
+ end
121
+
122
+ let(:server_2) do
123
+ double('server').tap do |server|
124
+ allow(server).to receive(:address).and_return(Mongo::Address.new('two'))
125
+ end
126
+ end
127
+
116
128
  let(:temp_cluster) do
117
129
  double('temp cluster').tap do |cluster|
118
- allow(cluster).to receive(:servers_list).and_return([
119
- double('server'),
120
- double('server'),
121
- ])
130
+ allow(cluster).to receive(:servers_list).and_return([server_1, server_2])
122
131
  end
123
132
  end
124
133
 
125
134
  it 'fails' do
126
135
  expect do
127
136
  topology
128
- end.to raise_error(ArgumentError, 'Cannot instantiate a single topology with more than one server in the cluster')
137
+ end.to raise_error(ArgumentError, /Cannot instantiate a single topology with more than one server in the cluster: one, two/)
129
138
  end
130
139
  end
131
140
  end
@@ -178,6 +178,9 @@ describe Mongo::Cluster do
178
178
  before do
179
179
  expect(server).to receive(:monitor).at_least(:once).and_return(monitor)
180
180
  expect(monitor).to receive(:scan!)
181
+
182
+ # scan! complains that there isn't a monitor on the server, calls summary
183
+ allow(monitor).to receive(:running?)
181
184
  end
182
185
 
183
186
  it 'returns true' do
@@ -20,12 +20,95 @@ describe Mongo::Collection::View::Explainable do
20
20
 
21
21
  describe '#explain' do
22
22
 
23
- let(:explain) do
24
- view.explain
23
+ shared_examples 'executes the explain' do
24
+ context '3.0+ server' do
25
+ min_server_fcv '3.0'
26
+
27
+ context 'not sharded' do
28
+ require_topology :single, :replica_set
29
+
30
+ it 'executes the explain' do
31
+ explain[:queryPlanner][:namespace].should == authorized_collection.namespace
32
+ end
33
+ end
34
+
35
+ context 'sharded' do
36
+ require_topology :sharded
37
+
38
+ context 'pre-3.2 server' do
39
+ max_server_version '3.0'
40
+
41
+ it 'executes the explain' do
42
+ explain[:queryPlanner][:parsedQuery].should be_a(Hash)
43
+ end
44
+ end
45
+
46
+ context '3.2+ server' do
47
+ min_server_fcv '3.2'
48
+
49
+ it 'executes the explain' do
50
+ explain[:queryPlanner][:mongosPlannerVersion].should == 1
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ context '2.6 server' do
57
+ max_server_version '2.6'
58
+
59
+ it 'executes the explain' do
60
+ explain[:cursor].should == 'BasicCursor'
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'without arguments' do
66
+ let(:explain) do
67
+ view.explain
68
+ end
69
+
70
+ include_examples 'executes the explain'
25
71
  end
26
72
 
27
- it 'executes an explain' do
28
- expect(explain[:cursor] == 'BasicCursor' || explain[:queryPlanner]).to be_truthy
73
+ context 'with verbosity argument' do
74
+ let(:explain) do
75
+ view.explain(verbosity: verbosity)
76
+ end
77
+
78
+ shared_examples 'triggers server error' do
79
+ # 3.0 does not produce the error.
80
+ min_server_fcv '3.2'
81
+
82
+ it 'triggers server error' do
83
+ lambda do
84
+ explain
85
+ end.should raise_error(Mongo::Error::OperationFailure, /verbosity string must be/)
86
+ end
87
+ end
88
+
89
+ context 'valid symbol value' do
90
+ let(:verbosity) { :query_planner }
91
+
92
+ include_examples 'executes the explain'
93
+ end
94
+
95
+ context 'valid string value' do
96
+ let(:verbosity) { 'executionStats' }
97
+
98
+ include_examples 'executes the explain'
99
+ end
100
+
101
+ context 'invalid symbol value' do
102
+ let(:verbosity) { :bogus }
103
+
104
+ include_examples 'triggers server error'
105
+ end
106
+
107
+ context 'invalid string value' do
108
+ let(:verbosity) { 'bogus' }
109
+
110
+ include_examples 'triggers server error'
111
+ end
29
112
  end
30
113
  end
31
114
  end
@@ -581,6 +581,7 @@ describe Mongo::Collection::View::MapReduce do
581
581
 
582
582
  context 'when the server is not valid for writing' do
583
583
  clean_slate
584
+ require_warning_clean
584
585
 
585
586
  before do
586
587
  stop_monitoring(authorized_client)
@@ -661,6 +662,7 @@ describe Mongo::Collection::View::MapReduce do
661
662
 
662
663
  context 'when the server is a valid for writing' do
663
664
  clean_slate
665
+ require_warning_clean
664
666
 
665
667
  before do
666
668
  stop_monitoring(authorized_client)
@@ -821,6 +821,38 @@ describe Mongo::Collection do
821
821
  end
822
822
  end
823
823
 
824
+ context 'when write concern passed in as an option' do
825
+ min_server_fcv '3.4'
826
+ require_topology :replica_set
827
+
828
+ before do
829
+ database['collection_spec'].drop
830
+ end
831
+
832
+ let(:events) do
833
+ subscriber.command_started_events('create')
834
+ end
835
+
836
+ let(:options) do
837
+ { write_concern: {w: 1} }
838
+ end
839
+
840
+ let!(:collection) do
841
+ authorized_collection.with(options)
842
+ end
843
+
844
+ let!(:command) do
845
+ Utils.get_command_event(authorized_client, 'create') do |client|
846
+ collection.create({ write_concern: {w: 2} })
847
+ end.command
848
+ end
849
+
850
+ it 'applies the write concern passed in as an option' do
851
+ expect(events.length).to eq(1)
852
+ expect(command[:writeConcern][:w]).to eq(2)
853
+ end
854
+ end
855
+
824
856
  context 'when the server does not support write concern on the create command' do
825
857
  max_server_version '3.2'
826
858
 
@@ -1059,6 +1091,34 @@ describe Mongo::Collection do
1059
1091
  end
1060
1092
  end
1061
1093
 
1094
+ context 'when write concern passed in as an option' do
1095
+ min_server_fcv '3.4'
1096
+ require_set_write_concern
1097
+
1098
+ let(:events) do
1099
+ subscriber.command_started_events('drop')
1100
+ end
1101
+
1102
+ let(:options) do
1103
+ { write_concern: {w: 1} }
1104
+ end
1105
+
1106
+ let!(:collection) do
1107
+ authorized_collection.with(options)
1108
+ end
1109
+
1110
+ let!(:command) do
1111
+ Utils.get_command_event(authorized_client, 'drop') do |client|
1112
+ collection.drop({ write_concern: {w: 0} })
1113
+ end.command
1114
+ end
1115
+
1116
+ it 'applies the write concern passed in as an option' do
1117
+ expect(events.length).to eq(1)
1118
+ expect(command[:writeConcern][:w]).to eq(0)
1119
+ end
1120
+ end
1121
+
1062
1122
  context 'when the server does not support write concern on the drop command' do
1063
1123
  max_server_version '3.2'
1064
1124