mongo 2.10.5 → 2.11.0.rc0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CONTRIBUTING.md +1 -1
- data/lib/mongo.rb +2 -0
- data/lib/mongo/address.rb +4 -0
- data/lib/mongo/address/validator.rb +99 -0
- data/lib/mongo/auth.rb +7 -2
- data/lib/mongo/auth/user.rb +1 -7
- data/lib/mongo/background_thread.rb +135 -0
- data/lib/mongo/bulk_write/transformable.rb +3 -3
- data/lib/mongo/client.rb +74 -16
- data/lib/mongo/cluster.rb +193 -41
- data/lib/mongo/cluster/periodic_executor.rb +31 -43
- data/lib/mongo/cluster/sdam_flow.rb +26 -3
- data/lib/mongo/cluster/srv_monitor.rb +127 -0
- data/lib/mongo/collection/view/readable.rb +3 -5
- data/lib/mongo/collection/view/writable.rb +3 -3
- data/lib/mongo/cursor/builder/get_more_command.rb +1 -4
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +5 -23
- data/lib/mongo/cursor/builder/op_get_more.rb +2 -2
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +5 -24
- data/lib/mongo/error.rb +1 -0
- data/lib/mongo/error/auth_error.rb +1 -1
- data/lib/mongo/error/connection_check_out_timeout.rb +7 -8
- data/lib/mongo/error/invalid_address.rb +24 -0
- data/lib/mongo/error/notable.rb +2 -2
- data/lib/mongo/error/operation_failure.rb +3 -3
- data/lib/mongo/error/pool_closed_error.rb +11 -4
- data/lib/mongo/event.rb +1 -1
- data/lib/mongo/grid/file.rb +0 -5
- data/lib/mongo/grid/file/chunk.rb +0 -2
- data/lib/mongo/grid/fs_bucket.rb +13 -15
- data/lib/mongo/grid/stream/write.rb +3 -9
- data/lib/mongo/loggable.rb +5 -1
- data/lib/mongo/monitoring.rb +1 -0
- data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +7 -0
- data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +11 -3
- data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +11 -3
- data/lib/mongo/monitoring/event/cmap/pool_closed.rb +11 -3
- data/lib/mongo/monitoring/event/cmap/pool_created.rb +12 -3
- data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +62 -0
- data/lib/mongo/operation/shared/executable.rb +5 -10
- data/lib/mongo/operation/shared/sessions_supported.rb +1 -5
- data/lib/mongo/protocol/get_more.rb +1 -2
- data/lib/mongo/protocol/kill_cursors.rb +13 -6
- data/lib/mongo/protocol/serializers.rb +4 -20
- data/lib/mongo/retryable.rb +9 -34
- data/lib/mongo/semaphore.rb +1 -1
- data/lib/mongo/server.rb +113 -42
- data/lib/mongo/server/connection.rb +12 -5
- data/lib/mongo/server/connection_pool.rb +250 -40
- data/lib/mongo/server/connection_pool/populator.rb +58 -0
- data/lib/mongo/server/description.rb +9 -2
- data/lib/mongo/server/monitor.rb +68 -93
- data/lib/mongo/server/monitor/connection.rb +2 -0
- data/lib/mongo/server_selector/selectable.rb +13 -5
- data/lib/mongo/session.rb +0 -13
- data/lib/mongo/srv.rb +17 -0
- data/lib/mongo/srv/monitor.rb +96 -0
- data/lib/mongo/srv/resolver.rb +130 -0
- data/lib/mongo/srv/result.rb +126 -0
- data/lib/mongo/srv/warning_result.rb +35 -0
- data/lib/mongo/uri.rb +45 -55
- data/lib/mongo/uri/srv_protocol.rb +89 -42
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +3 -4
- data/spec/README.md +6 -1
- data/spec/enterprise_auth/kerberos_spec.rb +7 -6
- data/spec/integration/change_stream_examples_spec.rb +0 -4
- data/spec/integration/client_construction_spec.rb +14 -2
- data/spec/integration/connect_single_rs_name_spec.rb +2 -2
- data/spec/integration/connection_pool_populator_spec.rb +296 -0
- data/spec/integration/connection_spec.rb +31 -22
- data/spec/integration/cursor_reaping_spec.rb +1 -2
- data/spec/integration/docs_examples_spec.rb +0 -4
- data/spec/integration/heartbeat_events_spec.rb +17 -15
- data/spec/integration/reconnect_spec.rb +144 -1
- data/spec/integration/retryable_writes_errors_spec.rb +0 -4
- data/spec/integration/retryable_writes_spec.rb +36 -36
- data/spec/integration/sdam_error_handling_spec.rb +31 -25
- data/spec/integration/sdam_events_spec.rb +2 -6
- data/spec/integration/server_monitor_spec.rb +28 -0
- data/spec/integration/server_selector_spec.rb +7 -5
- data/spec/integration/srv_monitoring_spec.rb +360 -0
- data/spec/integration/step_down_spec.rb +4 -6
- data/spec/lite_spec_helper.rb +22 -0
- data/spec/mongo/address/validator_spec.rb +51 -0
- data/spec/mongo/auth/cr_spec.rb +1 -29
- data/spec/mongo/auth/ldap_spec.rb +1 -29
- data/spec/mongo/auth/scram/conversation_spec.rb +0 -2
- data/spec/mongo/auth/scram/negotiation_spec.rb +1 -1
- data/spec/mongo/auth/scram_spec.rb +1 -29
- data/spec/mongo/auth/user/view_spec.rb +1 -36
- data/spec/mongo/auth/user_spec.rb +0 -12
- data/spec/mongo/auth/x509_spec.rb +1 -29
- data/spec/mongo/bulk_write_spec.rb +2 -2
- data/spec/mongo/client_construction_spec.rb +56 -15
- data/spec/mongo/client_spec.rb +31 -27
- data/spec/mongo/cluster/periodic_executor_spec.rb +16 -0
- data/spec/mongo/cluster/srv_monitor_spec.rb +214 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -11
- data/spec/mongo/cluster/topology/sharded_spec.rb +12 -9
- data/spec/mongo/cluster/topology/single_spec.rb +20 -11
- data/spec/mongo/cluster_spec.rb +45 -29
- data/spec/mongo/collection/view/map_reduce_spec.rb +14 -9
- data/spec/mongo/collection/view/readable_spec.rb +0 -16
- data/spec/mongo/collection_spec.rb +0 -44
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +2 -4
- data/spec/mongo/cursor/builder/op_get_more_spec.rb +2 -4
- data/spec/mongo/cursor_spec.rb +27 -7
- data/spec/mongo/monitoring/event/cmap/connection_checked_in_spec.rb +10 -3
- data/spec/mongo/monitoring/event/cmap/connection_checked_out_spec.rb +10 -3
- data/spec/mongo/monitoring/event/cmap/pool_closed_spec.rb +10 -3
- data/spec/mongo/monitoring/event/cmap/pool_created_spec.rb +10 -3
- data/spec/mongo/operation/delete/op_msg_spec.rb +17 -8
- data/spec/mongo/operation/insert/op_msg_spec.rb +50 -35
- data/spec/mongo/operation/update/op_msg_spec.rb +14 -7
- data/spec/mongo/retryable_spec.rb +52 -31
- data/spec/mongo/server/app_metadata_spec.rb +0 -8
- data/spec/mongo/server/connection_auth_spec.rb +5 -2
- data/spec/mongo/server/connection_pool/populator_spec.rb +101 -0
- data/spec/mongo/server/connection_pool_spec.rb +256 -107
- data/spec/mongo/server/connection_spec.rb +22 -33
- data/spec/mongo/server/description_spec.rb +42 -4
- data/spec/mongo/server/monitor/connection_spec.rb +22 -11
- data/spec/mongo/server/monitor_spec.rb +66 -107
- data/spec/mongo/server_spec.rb +82 -60
- data/spec/mongo/session/session_pool_spec.rb +1 -5
- data/spec/mongo/session_spec.rb +0 -4
- data/spec/mongo/socket/ssl_spec.rb +2 -2
- data/spec/mongo/srv/monitor_spec.rb +211 -0
- data/spec/mongo/srv/result_spec.rb +54 -0
- data/spec/mongo/uri/srv_protocol_spec.rb +30 -15
- data/spec/mongo/uri_spec.rb +125 -4
- data/spec/spec_helper.rb +6 -0
- data/spec/spec_tests/auth_spec.rb +39 -0
- data/spec/spec_tests/cmap_spec.rb +55 -8
- data/spec/spec_tests/connection_string_spec.rb +6 -31
- data/spec/spec_tests/data/auth/connection-string.yml +297 -0
- data/spec/spec_tests/data/cmap/pool-checkout-error-closed.yml +4 -1
- data/spec/spec_tests/data/cmap/pool-create-with-options.yml +1 -0
- data/spec/spec_tests/data/command_monitoring/insertMany.yml +1 -1
- data/spec/spec_tests/data/connection_string/invalid-uris.yml +20 -0
- data/spec/spec_tests/data/connection_string/valid-auth.yml +16 -0
- data/spec/spec_tests/data/connection_string/valid-warnings.yml +26 -30
- data/spec/spec_tests/data/transactions/abort.yml +3 -3
- data/spec/spec_tests/data/transactions/error-labels.yml +3 -3
- data/spec/spec_tests/data/transactions_api/callback-retry.yml +3 -3
- data/spec/spec_tests/data/uri_options/auth-options.yml +1 -1
- data/spec/spec_tests/max_staleness_spec.rb +7 -2
- data/spec/spec_tests/retryable_reads_spec.rb +0 -31
- data/spec/spec_tests/sdam_monitoring_spec.rb +12 -12
- data/spec/spec_tests/sdam_spec.rb +4 -7
- data/spec/spec_tests/server_selection_spec.rb +6 -2
- data/spec/spec_tests/transactions_spec.rb +0 -2
- data/spec/spec_tests/uri_options_spec.rb +4 -2
- data/spec/stress/connection_pool_stress_spec.rb +203 -0
- data/spec/stress/connection_pool_timing_spec.rb +181 -0
- data/spec/support/auth.rb +113 -0
- data/spec/support/background_thread_registry.rb +63 -0
- data/spec/support/client_registry.rb +11 -2
- data/spec/support/cluster_config.rb +65 -46
- data/spec/support/cluster_tools.rb +2 -2
- data/spec/support/cmap.rb +13 -14
- data/spec/support/cmap/verifier.rb +4 -5
- data/spec/support/command_monitoring.rb +0 -5
- data/spec/support/common_shortcuts.rb +101 -1
- data/spec/support/constraints.rb +25 -0
- data/spec/support/dns.rb +13 -0
- data/spec/support/event_subscriber.rb +0 -7
- data/spec/support/json_ext_formatter.rb +5 -1
- data/spec/support/lite_constraints.rb +22 -6
- data/spec/support/local_resource_registry.rb +34 -0
- data/spec/support/sdam_monitoring.rb +115 -0
- data/spec/support/spec_config.rb +20 -6
- data/spec/support/spec_setup.rb +2 -2
- data/spec/support/transactions.rb +1 -1
- data/spec/support/transactions/test.rb +1 -1
- data/spec/support/utils.rb +1 -16
- metadata +685 -659
- metadata.gz.sig +0 -0
- data/lib/mongo/event/description_changed.rb +0 -52
- data/spec/integration/bson_symbol_spec.rb +0 -34
- data/spec/integration/crud_spec.rb +0 -45
- data/spec/integration/get_more_spec.rb +0 -32
- data/spec/integration/grid_fs_bucket_spec.rb +0 -48
- data/spec/integration/retryable_errors_spec.rb +0 -265
- data/spec/integration/size_limit_spec.rb~12e1e9c4f... RUBY-2242 Fix zlib compression (#2021) +0 -98
- data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -56
- data/spec/runners/sdam/verifier.rb +0 -88
@@ -9,6 +9,7 @@ describe 'Step down behavior' do
|
|
9
9
|
before(:all) do
|
10
10
|
# These before/after blocks are run even if the tests themselves are
|
11
11
|
# skipped due to server version not being appropriate
|
12
|
+
ClientRegistry.instance.close_all_clients
|
12
13
|
if ClusterConfig.instance.fcv_ish >= '4.2' && ClusterConfig.instance.topology == :replica_set
|
13
14
|
# It seems that a short election timeout can cause unintended elections,
|
14
15
|
# which makes the server close connections which causes the driver to
|
@@ -160,8 +161,7 @@ describe 'Step down behavior' do
|
|
160
161
|
collection.insert_one(test: 1)
|
161
162
|
end.to raise_error(Mongo::Error::OperationFailure, /10107/)
|
162
163
|
|
163
|
-
|
164
|
-
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(0+1)
|
164
|
+
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(0)
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -180,8 +180,7 @@ describe 'Step down behavior' do
|
|
180
180
|
collection.insert_one(test: 1)
|
181
181
|
end.to raise_error(Mongo::Error::OperationFailure, /10107/)
|
182
182
|
|
183
|
-
|
184
|
-
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(1+1)
|
183
|
+
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(1)
|
185
184
|
end
|
186
185
|
end
|
187
186
|
|
@@ -198,8 +197,7 @@ describe 'Step down behavior' do
|
|
198
197
|
collection.insert_one(test: 1)
|
199
198
|
end.to raise_error(Mongo::Error::OperationFailure, /11600/)
|
200
199
|
|
201
|
-
|
202
|
-
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(1+1)
|
200
|
+
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(1)
|
203
201
|
end
|
204
202
|
end
|
205
203
|
end
|
data/spec/lite_spec_helper.rb
CHANGED
@@ -19,10 +19,13 @@ TRANSACTIONS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/transactions/*.ym
|
|
19
19
|
TRANSACTIONS_API_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/transactions_api/*.yml").sort
|
20
20
|
CHANGE_STREAMS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/change_streams/*.yml").sort
|
21
21
|
CMAP_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/cmap/*.yml").sort
|
22
|
+
AUTH_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/auth/*.yml").sort
|
22
23
|
|
23
24
|
require 'mongo'
|
24
25
|
require 'pp'
|
25
26
|
|
27
|
+
autoload :Benchmark, 'benchmark'
|
28
|
+
|
26
29
|
unless ENV['CI']
|
27
30
|
begin
|
28
31
|
require 'byebug'
|
@@ -37,6 +40,13 @@ unless ENV['CI']
|
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
43
|
+
if BSON::Environment.jruby?
|
44
|
+
require 'concurrent-ruby'
|
45
|
+
PossiblyConcurrentArray = Concurrent::Array
|
46
|
+
else
|
47
|
+
PossiblyConcurrentArray = Array
|
48
|
+
end
|
49
|
+
|
40
50
|
require 'support/spec_config'
|
41
51
|
|
42
52
|
Mongo::Logger.logger = Logger.new($stdout)
|
@@ -68,6 +78,8 @@ require 'support/client_registry_macros'
|
|
68
78
|
require 'support/json_ext_formatter'
|
69
79
|
require 'support/sdam_formatter_integration'
|
70
80
|
require 'support/utils'
|
81
|
+
require 'support/background_thread_registry'
|
82
|
+
require 'support/auth'
|
71
83
|
|
72
84
|
if SpecConfig.instance.mri?
|
73
85
|
require 'timeout_interrupt'
|
@@ -106,6 +118,16 @@ RSpec.configure do |config|
|
|
106
118
|
end
|
107
119
|
end
|
108
120
|
end
|
121
|
+
|
122
|
+
if SpecConfig.instance.ci?
|
123
|
+
unless BSON::Environment.jruby?
|
124
|
+
Rfc::Rif.output_object_space_stats = true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
config.expect_with :rspec do |c|
|
129
|
+
c.max_formatted_output_length = 10000
|
130
|
+
end
|
109
131
|
end
|
110
132
|
|
111
133
|
EventSubscriber.initialize
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'lite_spec_helper'
|
2
|
+
|
3
|
+
class ValidatorHost
|
4
|
+
include Mongo::Address::Validator
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Mongo::Address::Validator do
|
8
|
+
let(:host) { ValidatorHost.new }
|
9
|
+
|
10
|
+
describe '#validate_address_str!' do
|
11
|
+
shared_examples_for 'raises InvalidAddress' do
|
12
|
+
it 'raises InvalidAddress' do
|
13
|
+
expect do
|
14
|
+
host.validate_address_str!(address_str)
|
15
|
+
end.to raise_error(Mongo::Error::InvalidAddress)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
shared_examples_for 'passes validation' do
|
20
|
+
it 'passes validation' do
|
21
|
+
expect do
|
22
|
+
host.validate_address_str!(address_str)
|
23
|
+
end.not_to raise_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'leading dots' do
|
28
|
+
let(:address_str) { '.foo.bar.com' }
|
29
|
+
|
30
|
+
it_behaves_like 'raises InvalidAddress'
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'trailing dots' do
|
34
|
+
let(:address_str) { 'foo.bar.com.' }
|
35
|
+
|
36
|
+
it_behaves_like 'raises InvalidAddress'
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'runs of multiple dots' do
|
40
|
+
let(:address_str) { 'foo..bar.com' }
|
41
|
+
|
42
|
+
it_behaves_like 'raises InvalidAddress'
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'no dots' do
|
46
|
+
let(:address_str) { 'foo' }
|
47
|
+
|
48
|
+
it_behaves_like 'passes validation'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/mongo/auth/cr_spec.rb
CHANGED
@@ -2,36 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Auth::CR do
|
4
4
|
|
5
|
-
let(:address) do
|
6
|
-
default_address
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:monitoring) do
|
10
|
-
Mongo::Monitoring.new(monitoring: false)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:listeners) do
|
14
|
-
Mongo::Event::Listeners.new
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:cluster) do
|
18
|
-
double('cluster').tap do |cl|
|
19
|
-
allow(cl).to receive(:topology).and_return(topology)
|
20
|
-
allow(cl).to receive(:app_metadata).and_return(app_metadata)
|
21
|
-
allow(cl).to receive(:options).and_return({})
|
22
|
-
allow(cl).to receive(:cluster_time).and_return(nil)
|
23
|
-
allow(cl).to receive(:update_cluster_time)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
declare_topology_double
|
28
|
-
|
29
5
|
let(:server) do
|
30
|
-
|
31
|
-
SpecConfig.instance.test_options
|
32
|
-
).tap do |server|
|
33
|
-
server.scan!
|
34
|
-
end
|
6
|
+
authorized_client.cluster.next_primary
|
35
7
|
end
|
36
8
|
|
37
9
|
let(:connection) do
|
@@ -2,36 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Auth::LDAP do
|
4
4
|
|
5
|
-
let(:address) do
|
6
|
-
default_address
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:monitoring) do
|
10
|
-
Mongo::Monitoring.new(monitoring: false)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:listeners) do
|
14
|
-
Mongo::Event::Listeners.new
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:cluster) do
|
18
|
-
double('cluster').tap do |cl|
|
19
|
-
allow(cl).to receive(:topology).and_return(topology)
|
20
|
-
allow(cl).to receive(:app_metadata).and_return(app_metadata)
|
21
|
-
allow(cl).to receive(:options).and_return({})
|
22
|
-
allow(cl).to receive(:cluster_time).and_return(nil)
|
23
|
-
allow(cl).to receive(:update_cluster_time)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
declare_topology_double
|
28
|
-
|
29
5
|
let(:server) do
|
30
|
-
|
31
|
-
SpecConfig.instance.test_options
|
32
|
-
).tap do |server|
|
33
|
-
server.scan!
|
34
|
-
end
|
6
|
+
authorized_client.cluster.next_primary
|
35
7
|
end
|
36
8
|
|
37
9
|
let(:connection) do
|
@@ -57,7 +57,6 @@ describe Mongo::Auth::SCRAM::Conversation, retry: 3 do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#continue' do
|
60
|
-
fails_on_jruby
|
61
60
|
|
62
61
|
let(:reply) do
|
63
62
|
Mongo::Protocol::Message.new
|
@@ -125,7 +124,6 @@ describe Mongo::Auth::SCRAM::Conversation, retry: 3 do
|
|
125
124
|
end
|
126
125
|
|
127
126
|
describe '#finalize' do
|
128
|
-
fails_on_jruby
|
129
127
|
|
130
128
|
let(:continue_reply) do
|
131
129
|
Mongo::Protocol::Message.new
|
@@ -2,36 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Auth::SCRAM do
|
4
4
|
|
5
|
-
let(:address) do
|
6
|
-
default_address
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:monitoring) do
|
10
|
-
Mongo::Monitoring.new(monitoring: false)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:listeners) do
|
14
|
-
Mongo::Event::Listeners.new
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:cluster) do
|
18
|
-
double('cluster').tap do |cl|
|
19
|
-
allow(cl).to receive(:topology).and_return(topology)
|
20
|
-
allow(cl).to receive(:app_metadata).and_return(app_metadata)
|
21
|
-
allow(cl).to receive(:options).and_return({})
|
22
|
-
allow(cl).to receive(:cluster_time).and_return(nil)
|
23
|
-
allow(cl).to receive(:update_cluster_time)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
declare_topology_double
|
28
|
-
|
29
5
|
let(:server) do
|
30
|
-
|
31
|
-
SpecConfig.instance.test_options
|
32
|
-
).tap do |server|
|
33
|
-
server.scan!
|
34
|
-
end
|
6
|
+
authorized_client.cluster.next_primary
|
35
7
|
end
|
36
8
|
|
37
9
|
let(:connection) do
|
@@ -2,10 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Auth::User::View do
|
4
4
|
|
5
|
-
let(:database) { root_authorized_client.database }
|
6
|
-
|
7
5
|
let(:view) do
|
8
|
-
described_class.new(database)
|
6
|
+
described_class.new(root_authorized_client.database)
|
9
7
|
end
|
10
8
|
|
11
9
|
before do
|
@@ -14,39 +12,6 @@ describe Mongo::Auth::User::View do
|
|
14
12
|
|
15
13
|
describe '#create' do
|
16
14
|
|
17
|
-
context 'when password is not provided' do
|
18
|
-
|
19
|
-
let(:database) { root_authorized_client.use('$external').database }
|
20
|
-
|
21
|
-
let(:username) { 'passwordless-user' }
|
22
|
-
|
23
|
-
let(:response) do
|
24
|
-
view.create(
|
25
|
-
username,
|
26
|
-
# https://stackoverflow.com/questions/55939832/mongodb-external-database-cannot-create-new-user-with-user-defined-role
|
27
|
-
roles: [{role: 'read', db: 'admin'}],
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
before do
|
32
|
-
begin
|
33
|
-
view.remove(username)
|
34
|
-
rescue Mongo::Error::OperationFailure
|
35
|
-
# can be user not found, ignore
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'creates the user' do
|
40
|
-
view.info(username).should == []
|
41
|
-
|
42
|
-
lambda do
|
43
|
-
response
|
44
|
-
end.should_not raise_error
|
45
|
-
|
46
|
-
view.info(username).first['user'].should == username
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
15
|
context 'when a session is not used' do
|
51
16
|
|
52
17
|
let!(:response) do
|
@@ -284,16 +284,4 @@ describe Mongo::Auth::User do
|
|
284
284
|
end
|
285
285
|
end
|
286
286
|
end
|
287
|
-
|
288
|
-
describe '#spec' do
|
289
|
-
context 'when no password and no roles are set' do
|
290
|
-
let(:user) do
|
291
|
-
described_class.new(user: 'foo')
|
292
|
-
end
|
293
|
-
|
294
|
-
it 'is a hash with empty roles' do
|
295
|
-
user.spec.should == {roles: []}
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
299
287
|
end
|
@@ -2,36 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Auth::X509 do
|
4
4
|
|
5
|
-
let(:address) do
|
6
|
-
default_address
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:monitoring) do
|
10
|
-
Mongo::Monitoring.new(monitoring: false)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:listeners) do
|
14
|
-
Mongo::Event::Listeners.new
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:cluster) do
|
18
|
-
double('cluster').tap do |cl|
|
19
|
-
allow(cl).to receive(:topology).and_return(topology)
|
20
|
-
allow(cl).to receive(:app_metadata).and_return(app_metadata)
|
21
|
-
allow(cl).to receive(:options).and_return({})
|
22
|
-
allow(cl).to receive(:cluster_time).and_return(nil)
|
23
|
-
allow(cl).to receive(:update_cluster_time)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
declare_topology_double
|
28
|
-
|
29
5
|
let(:server) do
|
30
|
-
|
31
|
-
SpecConfig.instance.test_options
|
32
|
-
).tap do |server|
|
33
|
-
server.scan!
|
34
|
-
end
|
6
|
+
authorized_client.cluster.next_primary
|
35
7
|
end
|
36
8
|
|
37
9
|
let(:connection) do
|
@@ -1924,11 +1924,11 @@ describe Mongo::BulkWrite do
|
|
1924
1924
|
end
|
1925
1925
|
|
1926
1926
|
let(:first_txn_number) do
|
1927
|
-
|
1927
|
+
started_events[-2].command['txnNumber'].instance_variable_get(:@integer)
|
1928
1928
|
end
|
1929
1929
|
|
1930
1930
|
let(:second_txn_number) do
|
1931
|
-
|
1931
|
+
started_events[-1].command['txnNumber'].instance_variable_get(:@integer)
|
1932
1932
|
end
|
1933
1933
|
|
1934
1934
|
it 'inserts the documents' do
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongo::Client do
|
4
|
-
|
5
|
-
ClientRegistry.instance.close_all_clients
|
6
|
-
end
|
4
|
+
clean_slate
|
7
5
|
|
8
6
|
describe '.new' do
|
9
7
|
describe 'options' do
|
@@ -87,10 +85,9 @@ describe Mongo::Client do
|
|
87
85
|
# https://github.com/rspec/rspec-mocks/issues/1242.
|
88
86
|
#expect_any_instance_of(Mongo::Server::Monitor).to receive(:scan!).
|
89
87
|
# exactly(SpecConfig.instance.addresses.length).times.and_call_original
|
90
|
-
c =
|
88
|
+
c = new_local_client(
|
91
89
|
SpecConfig.instance.addresses, SpecConfig.instance.test_options)
|
92
90
|
expect(c.cluster.servers).not_to be_empty
|
93
|
-
c.close
|
94
91
|
end
|
95
92
|
|
96
93
|
# This checks the case of all initial seeds being removed from
|
@@ -120,19 +117,57 @@ describe Mongo::Client do
|
|
120
117
|
end
|
121
118
|
end
|
122
119
|
|
120
|
+
let(:logger) do
|
121
|
+
Logger.new(STDOUT, level: Logger::DEBUG)
|
122
|
+
end
|
123
|
+
|
124
|
+
let(:subscriber) do
|
125
|
+
Mongo::Monitoring::UnifiedSdamLogSubscriber.new(
|
126
|
+
logger: logger,
|
127
|
+
log_prefix: 'CCS-SDAM',
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
123
131
|
let(:client) do
|
124
132
|
ClientRegistry.instance.new_local_client(
|
125
133
|
[address],
|
126
134
|
# Specify server selection timeout here because test suite sets
|
127
135
|
# one by default and it's fairly low
|
128
|
-
SpecConfig.instance.test_options.merge(
|
136
|
+
SpecConfig.instance.test_options.merge(
|
137
|
+
connect_timeout: 1,
|
138
|
+
socket_timeout: 1,
|
139
|
+
server_selection_timeout: 8,
|
140
|
+
logger: logger,
|
141
|
+
log_prefix: 'CCS-CLIENT',
|
142
|
+
sdam_proc: lambda do |client|
|
143
|
+
subscriber.subscribe(client)
|
144
|
+
end
|
145
|
+
))
|
129
146
|
end
|
130
147
|
|
131
148
|
it 'does not wait for server selection timeout' do
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
149
|
+
time_taken = Benchmark.realtime do
|
150
|
+
# Client is created here.
|
151
|
+
client
|
152
|
+
end
|
153
|
+
puts "client_construction_spec.rb: Cluster is: #{client.cluster.summary}"
|
154
|
+
|
155
|
+
# Because the first round of sdam waits for server statuses to change
|
156
|
+
# rather than for server selection semaphore on the cluster which
|
157
|
+
# is signaled after topology is updated, the topology here could be
|
158
|
+
# old (i.e. a monitor thread was just about to update the topology
|
159
|
+
# but hasn't quite gotten to it. Add a small delay to compensate.
|
160
|
+
# This issue doesn't apply to real applications which will wait for
|
161
|
+
# server selection semaphore.
|
162
|
+
sleep 0.1
|
163
|
+
|
164
|
+
actual_class = client.cluster.topology.class
|
165
|
+
expect([
|
166
|
+
Mongo::Cluster::Topology::ReplicaSetWithPrimary,
|
167
|
+
Mongo::Cluster::Topology::Single,
|
168
|
+
Mongo::Cluster::Topology::Sharded,
|
169
|
+
]).to include(actual_class)
|
170
|
+
expect(time_taken).to be < 5
|
136
171
|
|
137
172
|
# run a command to ensure the client is a working one
|
138
173
|
client.database.command(ismaster: 1)
|
@@ -197,7 +232,8 @@ describe Mongo::Client do
|
|
197
232
|
context 'when compressors are provided' do
|
198
233
|
|
199
234
|
let(:client) do
|
200
|
-
new_local_client(SpecConfig.instance.addresses,
|
235
|
+
new_local_client(SpecConfig.instance.addresses,
|
236
|
+
SpecConfig.instance.all_test_options.merge(options))
|
201
237
|
end
|
202
238
|
|
203
239
|
context 'when the compressor is supported' do
|
@@ -1323,7 +1359,10 @@ describe Mongo::Client do
|
|
1323
1359
|
|
1324
1360
|
context 'when new client has a new cluster' do
|
1325
1361
|
let(:client) do
|
1326
|
-
new_local_client(['127.0.0.1:27017'],
|
1362
|
+
new_local_client(['127.0.0.1:27017'],
|
1363
|
+
database: SpecConfig.instance.test_db,
|
1364
|
+
server_selection_timeout: 0.5,
|
1365
|
+
socket_timeout: 0.1, connect_timeout: 0.1)
|
1327
1366
|
end
|
1328
1367
|
let(:new_client) do
|
1329
1368
|
client.with(app_name: 'client_construction_spec').tap do |new_client|
|
@@ -1359,12 +1398,14 @@ describe Mongo::Client do
|
|
1359
1398
|
let(:new_client) { client.with(database: 'foo') }
|
1360
1399
|
|
1361
1400
|
it 'does not copy sdam_proc option to new client' do
|
1362
|
-
client =
|
1401
|
+
client = new_local_client_nmio(['a'], sdam_proc: sdam_proc)
|
1363
1402
|
expect(new_client.options[:sdam_proc]).to be nil
|
1364
1403
|
end
|
1365
1404
|
|
1366
1405
|
it 'does not notify subscribers set up by sdam_proc' do
|
1367
|
-
client = new_local_client(['a'], sdam_proc: sdam_proc
|
1406
|
+
client = new_local_client(['a'], sdam_proc: sdam_proc,
|
1407
|
+
connect_timeout: 0.1, socket_timeout: 0.1,
|
1408
|
+
server_selection_timeout: 0.1)
|
1368
1409
|
expect(subscriber.started_events.length).to be > 0
|
1369
1410
|
subscriber.started_events.clear
|
1370
1411
|
|
@@ -1380,7 +1421,7 @@ describe Mongo::Client do
|
|
1380
1421
|
describe '#dup' do
|
1381
1422
|
|
1382
1423
|
let(:client) do
|
1383
|
-
|
1424
|
+
new_local_client_nmio(
|
1384
1425
|
['127.0.0.1:27017'],
|
1385
1426
|
:read => { :mode => :primary },
|
1386
1427
|
:database => SpecConfig.instance.test_db
|