mongo 2.14.0.rc1 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -1
  4. data/Rakefile +39 -4
  5. data/lib/mongo/address.rb +1 -1
  6. data/lib/mongo/collection.rb +5 -0
  7. data/lib/mongo/collection/view/readable.rb +4 -0
  8. data/lib/mongo/cursor.rb +15 -3
  9. data/lib/mongo/database/view.rb +1 -1
  10. data/lib/mongo/operation/collections_info/command.rb +5 -0
  11. data/lib/mongo/operation/collections_info/result.rb +16 -1
  12. data/lib/mongo/operation/find/result.rb +10 -0
  13. data/lib/mongo/server/description.rb +8 -1
  14. data/lib/mongo/session.rb +2 -1
  15. data/lib/mongo/version.rb +1 -1
  16. data/spec/README.md +7 -0
  17. data/spec/integration/bson_symbol_spec.rb +4 -2
  18. data/spec/integration/change_stream_spec.rb +1 -1
  19. data/spec/integration/connection_pool_populator_spec.rb +1 -1
  20. data/spec/integration/cursor_reaping_spec.rb +1 -1
  21. data/spec/integration/fork_reconnect_spec.rb +56 -1
  22. data/spec/integration/query_cache_transactions_spec.rb +29 -18
  23. data/spec/integration/sdam_error_handling_spec.rb +17 -0
  24. data/spec/integration/sdam_events_spec.rb +8 -5
  25. data/spec/integration/transactions_examples_spec.rb +17 -7
  26. data/spec/lite_spec_helper.rb +5 -3
  27. data/spec/mongo/auth/user_spec.rb +1 -1
  28. data/spec/mongo/bulk_write_spec.rb +2 -2
  29. data/spec/mongo/client_construction_spec.rb +3 -3
  30. data/spec/mongo/client_encryption_spec.rb +16 -10
  31. data/spec/mongo/client_spec.rb +7 -0
  32. data/spec/mongo/cluster/topology/replica_set_spec.rb +1 -1
  33. data/spec/mongo/cluster/topology/sharded_spec.rb +1 -1
  34. data/spec/mongo/cluster/topology/single_spec.rb +1 -1
  35. data/spec/mongo/cluster/topology/unknown_spec.rb +1 -1
  36. data/spec/mongo/cluster/topology_spec.rb +1 -1
  37. data/spec/mongo/collection/view/change_stream_resume_spec.rb +1 -1
  38. data/spec/mongo/collection/view/readable_spec.rb +36 -0
  39. data/spec/mongo/collection_spec.rb +12 -0
  40. data/spec/mongo/crypt/binary_spec.rb +1 -6
  41. data/spec/mongo/crypt/binding/binary_spec.rb +1 -6
  42. data/spec/mongo/crypt/binding/context_spec.rb +2 -7
  43. data/spec/mongo/crypt/binding/helpers_spec.rb +1 -6
  44. data/spec/mongo/crypt/binding/mongocrypt_spec.rb +2 -7
  45. data/spec/mongo/crypt/binding/status_spec.rb +1 -6
  46. data/spec/mongo/crypt/binding/version_spec.rb +1 -6
  47. data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
  48. data/spec/mongo/crypt/status_spec.rb +1 -6
  49. data/spec/mongo/database_spec.rb +64 -0
  50. data/spec/mongo/monitoring/event/server_closed_spec.rb +1 -1
  51. data/spec/mongo/monitoring/event/server_opening_spec.rb +1 -1
  52. data/spec/mongo/monitoring/event/topology_changed_spec.rb +1 -1
  53. data/spec/mongo/monitoring/event/topology_closed_spec.rb +1 -1
  54. data/spec/mongo/monitoring/event/topology_opening_spec.rb +1 -1
  55. data/spec/mongo/operation/delete/op_msg_spec.rb +3 -3
  56. data/spec/mongo/operation/insert/command_spec.rb +2 -2
  57. data/spec/mongo/operation/insert/op_msg_spec.rb +3 -3
  58. data/spec/mongo/operation/read_preference_op_msg_spec.rb +1 -1
  59. data/spec/mongo/operation/update/command_spec.rb +2 -2
  60. data/spec/mongo/operation/update/op_msg_spec.rb +3 -3
  61. data/spec/mongo/query_cache_spec.rb +1 -0
  62. data/spec/mongo/server/app_metadata_shared.rb +2 -2
  63. data/spec/mongo/server/connection_spec.rb +1 -1
  64. data/spec/mongo/server/description_spec.rb +18 -0
  65. data/spec/mongo/server_selector_spec.rb +2 -2
  66. data/spec/mongo/socket/ssl_spec.rb +3 -3
  67. data/spec/runners/change_streams/test.rb +1 -1
  68. data/spec/runners/crud/test_base.rb +0 -19
  69. data/spec/runners/server_selection.rb +1 -1
  70. data/spec/runners/transactions/test.rb +2 -2
  71. data/spec/shared/LICENSE +20 -0
  72. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  73. data/spec/shared/lib/mrss/constraints.rb +303 -0
  74. data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
  75. data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
  76. data/spec/spec_helper.rb +3 -1
  77. data/spec/stress/fork_reconnect_stress_spec.rb +1 -1
  78. data/spec/support/constraints.rb +0 -270
  79. data/spec/support/utils.rb +19 -0
  80. metadata +956 -952
  81. metadata.gz.sig +0 -0
  82. data/spec/support/child_process_helper.rb +0 -78
  83. data/spec/support/lite_constraints.rb +0 -165
  84. data/spec/support/spec_organizer.rb +0 -129
@@ -19,6 +19,7 @@ describe 'SDAM error handling' do
19
19
  new_local_client(SpecConfig.instance.addresses,
20
20
  SpecConfig.instance.all_test_options.merge(
21
21
  socket_timeout: 3, connect_timeout: 3,
22
+ heartbeat_frequency: 100,
22
23
  # Uncomment to print all events to stdout:
23
24
  #sdam_proc: Utils.subscribe_all_sdam_proc(diagnostic_subscriber),
24
25
  **Utils.disable_retries_client_options)
@@ -28,6 +29,14 @@ describe 'SDAM error handling' do
28
29
  let(:server) { client.cluster.next_primary }
29
30
 
30
31
  shared_examples_for 'marks server unknown' do
32
+ before do
33
+ server.monitor.stop!
34
+ end
35
+
36
+ after do
37
+ client.close
38
+ end
39
+
31
40
  it 'marks server unknown' do
32
41
  expect(server).not_to be_unknown
33
42
  RSpec::Mocks.with_temporary_scope do
@@ -38,6 +47,14 @@ describe 'SDAM error handling' do
38
47
  end
39
48
 
40
49
  shared_examples_for 'does not mark server unknown' do
50
+ before do
51
+ server.monitor.stop!
52
+ end
53
+
54
+ after do
55
+ client.close
56
+ end
57
+
41
58
  it 'does not mark server unknown' do
42
59
  expect(server).not_to be_unknown
43
60
  RSpec::Mocks.with_temporary_scope do
@@ -69,7 +69,8 @@ describe 'SDAM events' do
69
69
  succeeded_events = subscriber.select_succeeded_events(Mongo::Monitoring::Event::ServerHeartbeatSucceeded)
70
70
  # Since we gracefully close the client, we expect each heartbeat
71
71
  # to complete.
72
- started_events.length.should == succeeded_events.length
72
+ started_events.length.should > 1
73
+ (succeeded_events.length-1..succeeded_events.length).should include(started_events.length)
73
74
  end
74
75
  end
75
76
 
@@ -105,10 +106,12 @@ describe 'SDAM events' do
105
106
  (succeeded_awaited = events.select(&:awaited?)).should_not be_empty
106
107
  (succeeded_regular = events.reject(&:awaited?)).should_not be_empty
107
108
 
108
- # Since we gracefully close the client, we expect each heartbeat
109
- # to complete.
110
- started_awaited.length.should == succeeded_awaited.length
111
- started_regular.length.should == succeeded_regular.length
109
+ # There may be in-flight ismasters that don't complete, both
110
+ # regular and awaited.
111
+ started_awaited.length.should > 1
112
+ (succeeded_awaited.length-1..succeeded_awaited.length).should include(started_awaited.length)
113
+ started_regular.length.should > 1
114
+ (succeeded_regular.length-1..succeeded_regular.length).should include(started_regular.length)
112
115
  end
113
116
  end
114
117
  end
@@ -4,28 +4,42 @@ describe 'Transactions examples' do
4
4
  require_wired_tiger
5
5
  require_transaction_support
6
6
 
7
+ let(:client) do
8
+ authorized_client.with(read_concern: {level: :majority}, write: {w: :majority})
9
+ end
10
+
7
11
  let(:hr) do
8
- authorized_client.use(:hr).database
12
+ client.use(:hr).database
9
13
  end
10
14
 
11
15
  let(:reporting) do
12
- authorized_client.use(:reporting).database
16
+ client.use(:reporting).database
13
17
  end
14
18
 
15
19
  before(:each) do
16
20
  hr[:employees].insert_one(employee: 3, status: 'Active')
21
+
22
+ # Sanity check since this test likes to fail
23
+ employee = hr[:employees].find({ employee: 3 }, limit: 1).first
24
+ expect(employee).to_not be_nil
25
+
17
26
  reporting[:events].insert_one(employee: 3, status: { new: 'Active', old: nil})
18
27
  end
19
28
 
20
29
  after(:each) do
21
30
  hr.drop
22
31
  reporting.drop
32
+
33
+ # Work around https://jira.mongodb.org/browse/SERVER-53015
34
+ ::Utils.mongos_each_direct_client do |client|
35
+ client.database.command(flushRouterConfig: 1)
36
+ end
23
37
  end
24
38
 
25
39
  context 'individual examples' do
26
40
 
27
41
  let(:session) do
28
- authorized_client.start_session
42
+ client.start_session
29
43
  end
30
44
 
31
45
  # Start Transactions Intro Example 1
@@ -142,10 +156,6 @@ describe 'Transactions examples' do
142
156
 
143
157
  context 'Transactions Retry Example 3 (combined example)' do
144
158
 
145
- let(:client) do
146
- authorized_client
147
- end
148
-
149
159
  let(:run_transaction) do
150
160
 
151
161
  # Start Transactions Retry Example 3
@@ -1,3 +1,5 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "shared", "lib"))
2
+
1
3
  COVERAGE_MIN = 90
2
4
  CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
3
5
 
@@ -67,8 +69,8 @@ unless SpecConfig.instance.client_debug?
67
69
  end
68
70
  Encoding.default_external = Encoding::UTF_8
69
71
 
72
+ require 'mrss/lite_constraints'
70
73
  require 'support/matchers'
71
- require 'support/lite_constraints'
72
74
  require 'support/event_subscriber'
73
75
  require 'support/common_shortcuts'
74
76
  require 'support/client_registry'
@@ -89,7 +91,7 @@ end
89
91
  RSpec.configure do |config|
90
92
  config.extend(CommonShortcuts::ClassMethods)
91
93
  config.include(CommonShortcuts::InstanceMethods)
92
- config.extend(LiteConstraints)
94
+ config.extend(Mrss::LiteConstraints)
93
95
  config.include(ClientRegistryMacros)
94
96
 
95
97
  if SpecConfig.instance.ci?
@@ -106,7 +108,7 @@ RSpec.configure do |config|
106
108
  end
107
109
  end
108
110
 
109
- if SpecConfig.instance.ci?
111
+ if SpecConfig.instance.ci? && !%w(1 true yes).include?(ENV['INTERACTIVE']&.downcase)
110
112
  # Allow a max of 30 seconds per test.
111
113
  # Tests should take under 10 seconds ideally but it seems
112
114
  # we have some that run for more than 10 seconds in CI.
@@ -55,7 +55,7 @@ describe Mongo::Auth::User do
55
55
  let(:options) { {auth_mech: 'scram'} }
56
56
 
57
57
  context 'not linting' do
58
- skip_if_linting
58
+ require_no_linting
59
59
 
60
60
  it 'warns' do
61
61
  expect(Mongo::Logger.logger).to receive(:warn)
@@ -1335,7 +1335,7 @@ describe Mongo::BulkWrite do
1335
1335
  context 'when the number of updates exceeds the max batch size' do
1336
1336
  # Test uses doubles for server descriptions, doubles are
1337
1337
  # incompatible with freezing which linting does for descriptions
1338
- skip_if_linting
1338
+ require_no_linting
1339
1339
 
1340
1340
  let(:batch_size) do
1341
1341
  11
@@ -2012,7 +2012,7 @@ describe Mongo::BulkWrite do
2012
2012
  context 'when the operations need to be split' do
2013
2013
  # Test uses doubles for server descriptions, doubles are
2014
2014
  # incompatible with freezing which linting does for descriptions
2015
- skip_if_linting
2015
+ require_no_linting
2016
2016
 
2017
2017
  let(:batch_size) do
2018
2018
  11
@@ -845,7 +845,7 @@ describe Mongo::Client do
845
845
  end
846
846
 
847
847
  context 'mri' do
848
- only_mri
848
+ require_mri
849
849
 
850
850
  let(:platform_string) do
851
851
  [
@@ -1312,7 +1312,7 @@ describe Mongo::Client do
1312
1312
  end
1313
1313
 
1314
1314
  context 'when not linting' do
1315
- skip_if_linting
1315
+ require_no_linting
1316
1316
 
1317
1317
  it 'rejects bogus read preference as symbol' do
1318
1318
  expect do
@@ -1359,7 +1359,7 @@ describe Mongo::Client do
1359
1359
  end
1360
1360
 
1361
1361
  context 'when read concern has an invalid key' do
1362
- skip_if_linting
1362
+ require_no_linting
1363
1363
 
1364
1364
  let(:options) do
1365
1365
  { read_concern: { hello: :local } }
@@ -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 invalid endpoint' do
271
+ context 'with https' do
272
272
  let(:options) do
273
273
  {
274
274
  master_key: {
@@ -279,20 +279,26 @@ describe Mongo::ClientEncryption do
279
279
  }
280
280
  end
281
281
 
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
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
+ }
290
294
  end
291
295
 
292
296
  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
293
299
  expect do
294
300
  data_key_id
295
- end.to raise_error(Mongo::Error::KmsError, expected_message)
301
+ end.to raise_error(Mongo::Error::KmsError, /SocketError/)
296
302
  end
297
303
  end
298
304
 
@@ -727,6 +727,13 @@ describe Mongo::Client do
727
727
  expect(new_id).not_to eql(old_id)
728
728
  end
729
729
 
730
+ it 'replaces the session pool' do
731
+ old_id = client.cluster.session_pool.object_id
732
+ client.reconnect
733
+ new_id = client.cluster.session_pool.object_id
734
+ expect(new_id).not_to eql(old_id)
735
+ end
736
+
730
737
  it 'returns true' do
731
738
  expect(client.reconnect).to be(true)
732
739
  end
@@ -565,7 +565,7 @@ describe Mongo::Cluster::Topology::ReplicaSetNoPrimary do
565
565
  end
566
566
 
567
567
  describe '#summary' do
568
- skip_if_linting
568
+ require_no_linting
569
569
 
570
570
  let(:desc) do
571
571
  Mongo::Server::Description.new(Mongo::Address.new('127.0.0.2:27017'))
@@ -135,7 +135,7 @@ describe Mongo::Cluster::Topology::Sharded do
135
135
  end
136
136
 
137
137
  describe '#summary' do
138
- skip_if_linting
138
+ require_no_linting
139
139
 
140
140
  let(:desc1) do
141
141
  Mongo::Server::Description.new(Mongo::Address.new('127.0.0.2:27017'))
@@ -175,7 +175,7 @@ describe Mongo::Cluster::Topology::Single do
175
175
  end
176
176
 
177
177
  describe '#summary' do
178
- skip_if_linting
178
+ require_no_linting
179
179
 
180
180
  let(:desc) do
181
181
  Mongo::Server::Description.new(Mongo::Address.new('127.0.0.2:27017'))
@@ -86,7 +86,7 @@ describe Mongo::Cluster::Topology::Unknown do
86
86
  end
87
87
 
88
88
  describe '#summary' do
89
- skip_if_linting
89
+ require_no_linting
90
90
 
91
91
  let(:desc) do
92
92
  Mongo::Server::Description.new(Mongo::Address.new('127.0.0.2:27017'))
@@ -111,7 +111,7 @@ describe Mongo::Cluster::Topology do
111
111
  end
112
112
 
113
113
  describe '#logical_session_timeout' do
114
- skip_if_linting
114
+ require_no_linting
115
115
 
116
116
  let(:listeners) do
117
117
  Mongo::Event::Listeners.new
@@ -183,7 +183,7 @@ describe Mongo::Collection::View::ChangeStream do
183
183
 
184
184
  context 'when a killCursors command is issued for the cursor' do
185
185
  context 'using Enumerable' do
186
- only_mri
186
+ require_mri
187
187
 
188
188
  before do
189
189
  change_stream
@@ -602,6 +602,42 @@ describe Mongo::Collection::View::Readable do
602
602
  end
603
603
  end
604
604
 
605
+ describe "#estimated_document_count" do
606
+
607
+ let(:documents) do
608
+ (1..10).map{ |i| { field: "test#{i}" }}
609
+ end
610
+
611
+ before do
612
+ authorized_collection.delete_many
613
+ authorized_collection.insert_many(documents)
614
+ end
615
+
616
+ let(:result) do
617
+ view.estimated_document_count(options)
618
+ end
619
+
620
+ context 'when a selector is provided' do
621
+
622
+ let(:selector) do
623
+ { field: 'test1' }
624
+ end
625
+
626
+ it 'raises an error' do
627
+ expect {
628
+ result
629
+ }.to raise_error(ArgumentError, "Cannot call estimated_document_count when querying with a filter")
630
+ end
631
+ end
632
+
633
+ context 'when no selector is provided' do
634
+
635
+ it 'returns the estimated count of matching documents' do
636
+ expect(view.estimated_document_count).to eq(10)
637
+ end
638
+ end
639
+ end
640
+
605
641
  describe '#distinct' do
606
642
 
607
643
  context 'when incorporating read concern' do
@@ -1845,6 +1845,18 @@ describe Mongo::Collection do
1845
1845
  end
1846
1846
  end
1847
1847
 
1848
+ context 'when the document is nil' do
1849
+ let(:result) do
1850
+ authorized_collection.insert_one(nil)
1851
+ end
1852
+
1853
+ it 'raises an ArgumentError' do
1854
+ expect {
1855
+ result
1856
+ }.to raise_error(ArgumentError, "Document to be inserted cannot be nil")
1857
+ end
1858
+ end
1859
+
1848
1860
  context 'when the insert fails' do
1849
1861
 
1850
1862
  let(:result) do
@@ -1,9 +1,4 @@
1
- require 'mongo'
2
- require 'support/lite_constraints'
3
-
4
- RSpec.configure do |config|
5
- config.extend(LiteConstraints)
6
- end
1
+ require 'lite_spec_helper'
7
2
 
8
3
  describe Mongo::Crypt::Binary do
9
4
  require_libmongocrypt
@@ -1,9 +1,4 @@
1
- require 'mongo'
2
- require 'support/lite_constraints'
3
-
4
- RSpec.configure do |config|
5
- config.extend(LiteConstraints)
6
- end
1
+ require 'lite_spec_helper'
7
2
 
8
3
  describe 'Mongo::Crypt::Binding' do
9
4
  describe 'binary_t bindings' do
@@ -1,10 +1,5 @@
1
- require 'mongo'
2
- require 'support/lite_constraints'
3
- require 'mongo/crypt/helpers/mongo_crypt_spec_helper'
4
-
5
- RSpec.configure do |config|
6
- config.extend(LiteConstraints)
7
- end
1
+ require 'lite_spec_helper'
2
+ require_relative '../helpers/mongo_crypt_spec_helper'
8
3
 
9
4
  shared_context 'initialized for data key creation' do
10
5
  let(:master_key) { "ru\xfe\x00" * 24 }
@@ -1,9 +1,4 @@
1
- require 'mongo'
2
- require 'support/lite_constraints'
3
-
4
- RSpec.configure do |config|
5
- config.extend(LiteConstraints)
6
- end
1
+ require 'lite_spec_helper'
7
2
 
8
3
  describe 'Mongo::Crypt::Binding' do
9
4
  describe 'helper methods' do
@@ -1,10 +1,5 @@
1
- require 'mongo'
2
- require 'support/lite_constraints'
3
- require 'mongo/crypt/helpers/mongo_crypt_spec_helper'
4
-
5
- RSpec.configure do |config|
6
- config.extend(LiteConstraints)
7
- end
1
+ require 'lite_spec_helper'
2
+ require_relative '../helpers/mongo_crypt_spec_helper'
8
3
 
9
4
  describe 'Mongo::Crypt::Binding' do
10
5
  describe 'mongocrypt_t binding' do