mongo 2.13.1 → 2.14.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -4
- data/lib/mongo.rb +9 -0
- data/lib/mongo/address/ipv4.rb +1 -1
- data/lib/mongo/address/ipv6.rb +1 -1
- data/lib/mongo/bulk_write.rb +17 -0
- data/lib/mongo/caching_cursor.rb +74 -0
- data/lib/mongo/client.rb +47 -8
- data/lib/mongo/cluster.rb +3 -3
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/collection.rb +26 -0
- data/lib/mongo/collection/view.rb +24 -20
- data/lib/mongo/collection/view/aggregation.rb +25 -4
- data/lib/mongo/collection/view/builder/find_command.rb +38 -18
- data/lib/mongo/collection/view/explainable.rb +27 -8
- data/lib/mongo/collection/view/iterable.rb +72 -12
- data/lib/mongo/collection/view/readable.rb +12 -2
- data/lib/mongo/collection/view/writable.rb +15 -1
- data/lib/mongo/crypt/encryption_io.rb +6 -6
- data/lib/mongo/cursor.rb +1 -0
- data/lib/mongo/database.rb +6 -0
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/error/invalid_read_concern.rb +28 -0
- data/lib/mongo/error/server_certificate_revoked.rb +22 -0
- data/lib/mongo/error/unsupported_option.rb +14 -12
- data/lib/mongo/lint.rb +2 -1
- data/lib/mongo/logger.rb +3 -3
- data/lib/mongo/operation.rb +2 -0
- data/lib/mongo/operation/aggregate/result.rb +9 -8
- data/lib/mongo/operation/collections_info/result.rb +2 -0
- data/lib/mongo/operation/delete/bulk_result.rb +2 -0
- data/lib/mongo/operation/delete/result.rb +3 -0
- data/lib/mongo/operation/explain/command.rb +4 -0
- data/lib/mongo/operation/explain/legacy.rb +4 -0
- data/lib/mongo/operation/explain/op_msg.rb +6 -0
- data/lib/mongo/operation/explain/result.rb +3 -0
- data/lib/mongo/operation/find/legacy/result.rb +2 -0
- data/lib/mongo/operation/find/result.rb +3 -0
- data/lib/mongo/operation/get_more/result.rb +3 -0
- data/lib/mongo/operation/indexes/result.rb +5 -0
- data/lib/mongo/operation/insert/bulk_result.rb +5 -0
- data/lib/mongo/operation/insert/result.rb +5 -0
- data/lib/mongo/operation/list_collections/result.rb +5 -0
- data/lib/mongo/operation/map_reduce/result.rb +10 -0
- data/lib/mongo/operation/parallel_scan/result.rb +4 -0
- data/lib/mongo/operation/result.rb +35 -6
- data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
- data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
- data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
- data/lib/mongo/operation/shared/executable.rb +1 -0
- data/lib/mongo/operation/shared/idable.rb +2 -1
- data/lib/mongo/operation/shared/limited.rb +1 -0
- data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
- data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
- data/lib/mongo/operation/shared/sessions_supported.rb +1 -0
- data/lib/mongo/operation/shared/specifiable.rb +1 -0
- data/lib/mongo/operation/shared/write.rb +1 -0
- data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
- data/lib/mongo/operation/update/legacy/result.rb +7 -0
- data/lib/mongo/operation/update/result.rb +8 -0
- data/lib/mongo/operation/users_info/result.rb +3 -0
- data/lib/mongo/query_cache.rb +242 -0
- data/lib/mongo/retryable.rb +8 -1
- data/lib/mongo/server.rb +5 -1
- data/lib/mongo/server/connection_common.rb +2 -2
- data/lib/mongo/server/connection_pool.rb +3 -0
- data/lib/mongo/server/monitor.rb +1 -1
- data/lib/mongo/server/monitor/connection.rb +3 -3
- data/lib/mongo/server/pending_connection.rb +2 -2
- data/lib/mongo/server/push_monitor.rb +1 -1
- data/lib/mongo/server_selector/base.rb +5 -1
- data/lib/mongo/session.rb +3 -0
- data/lib/mongo/socket.rb +6 -4
- data/lib/mongo/socket/ocsp_cache.rb +97 -0
- data/lib/mongo/socket/ocsp_verifier.rb +368 -0
- data/lib/mongo/socket/ssl.rb +45 -24
- data/lib/mongo/srv/monitor.rb +7 -13
- data/lib/mongo/srv/resolver.rb +14 -10
- data/lib/mongo/timeout.rb +2 -0
- data/lib/mongo/uri.rb +21 -390
- data/lib/mongo/uri/options_mapper.rb +582 -0
- data/lib/mongo/uri/srv_protocol.rb +3 -2
- data/lib/mongo/utils.rb +12 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/NOTES.aws-auth.md +12 -7
- data/spec/README.md +56 -1
- data/spec/integration/bulk_write_spec.rb +48 -0
- data/spec/integration/client_authentication_options_spec.rb +55 -28
- data/spec/integration/connection_pool_populator_spec.rb +3 -1
- data/spec/integration/cursor_reaping_spec.rb +53 -17
- data/spec/integration/ocsp_connectivity_spec.rb +26 -0
- data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
- data/spec/integration/ocsp_verifier_spec.rb +334 -0
- data/spec/integration/query_cache_spec.rb +1045 -0
- data/spec/integration/query_cache_transactions_spec.rb +179 -0
- data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
- data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
- data/spec/integration/sdam_error_handling_spec.rb +68 -0
- data/spec/integration/server_selection_spec.rb +36 -0
- data/spec/integration/srv_monitoring_spec.rb +38 -3
- data/spec/integration/srv_spec.rb +56 -0
- data/spec/lite_spec_helper.rb +3 -1
- data/spec/mongo/address_spec.rb +1 -1
- data/spec/mongo/caching_cursor_spec.rb +70 -0
- data/spec/mongo/client_construction_spec.rb +54 -1
- data/spec/mongo/client_spec.rb +40 -0
- data/spec/mongo/cluster/topology/single_spec.rb +14 -5
- data/spec/mongo/cluster_spec.rb +3 -0
- data/spec/mongo/collection/view/explainable_spec.rb +87 -4
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
- data/spec/mongo/collection_spec.rb +60 -0
- data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
- data/spec/mongo/database_spec.rb +44 -0
- data/spec/mongo/error/no_server_available_spec.rb +1 -1
- data/spec/mongo/logger_spec.rb +13 -11
- data/spec/mongo/query_cache_spec.rb +279 -0
- data/spec/mongo/server/connection_pool_spec.rb +7 -3
- data/spec/mongo/server/connection_spec.rb +14 -7
- data/spec/mongo/socket/ssl_spec.rb +1 -1
- data/spec/mongo/socket_spec.rb +1 -1
- data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
- data/spec/mongo/uri_option_parsing_spec.rb +11 -11
- data/spec/mongo/uri_spec.rb +68 -41
- data/spec/mongo/utils_spec.rb +39 -0
- data/spec/runners/auth.rb +3 -0
- data/spec/runners/connection_string.rb +35 -124
- data/spec/spec_tests/cmap_spec.rb +7 -3
- data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
- data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
- data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
- data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
- data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
- data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
- data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
- data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
- data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
- data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
- data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
- data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
- data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
- data/spec/spec_tests/uri_options_spec.rb +31 -33
- data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
- data/spec/support/certificates/atlas-ocsp.crt +41 -0
- data/spec/support/client_registry_macros.rb +11 -2
- data/spec/support/common_shortcuts.rb +45 -0
- data/spec/support/constraints.rb +23 -0
- data/spec/support/lite_constraints.rb +24 -0
- data/spec/support/matchers.rb +16 -0
- data/spec/support/ocsp +1 -0
- data/spec/support/session_registry.rb +52 -0
- data/spec/support/spec_config.rb +22 -0
- data/spec/support/utils.rb +19 -1
- metadata +38 -3
- metadata.gz.sig +0 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'QueryCache with transactions' do
|
4
|
+
around do |spec|
|
5
|
+
Mongo::QueryCache.clear
|
6
|
+
Mongo::QueryCache.cache { spec.run }
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
authorized_collection.delete_many
|
11
|
+
subscriber.clear_events!
|
12
|
+
end
|
13
|
+
|
14
|
+
# These tests do not currently use the session registry because transactions
|
15
|
+
# leak sessions independently of the query cache. This will be resolved by
|
16
|
+
# RUBY-2391.
|
17
|
+
|
18
|
+
let(:subscriber) { EventSubscriber.new }
|
19
|
+
|
20
|
+
let(:client) do
|
21
|
+
authorized_client.tap do |client|
|
22
|
+
client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:authorized_collection) { client['collection_spec'] }
|
27
|
+
|
28
|
+
describe 'in transactions' do
|
29
|
+
require_transaction_support
|
30
|
+
require_wired_tiger
|
31
|
+
|
32
|
+
let(:collection) { authorized_client['test'] }
|
33
|
+
|
34
|
+
let(:events) do
|
35
|
+
subscriber.command_started_events('find')
|
36
|
+
end
|
37
|
+
|
38
|
+
before do
|
39
|
+
Utils.create_collection(authorized_client, 'test')
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with convenient API' do
|
43
|
+
context 'when same query is performed inside and outside of transaction' do
|
44
|
+
it 'performs one query' do
|
45
|
+
collection.find.to_a
|
46
|
+
|
47
|
+
session = authorized_client.start_session
|
48
|
+
session.with_transaction do
|
49
|
+
collection.find({}, session: session).to_a
|
50
|
+
end
|
51
|
+
|
52
|
+
expect(subscriber.command_started_events('find').length).to eq(1)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when transaction has a different read concern' do
|
57
|
+
it 'performs two queries' do
|
58
|
+
collection.find.to_a
|
59
|
+
|
60
|
+
session = authorized_client.start_session
|
61
|
+
session.with_transaction(
|
62
|
+
read_concern: { level: :snapshot }
|
63
|
+
) do
|
64
|
+
collection.find({}, session: session).to_a
|
65
|
+
end
|
66
|
+
|
67
|
+
expect(subscriber.command_started_events('find').length).to eq(2)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when transaction has a different read preference' do
|
72
|
+
it 'performs two queries' do
|
73
|
+
collection.find.to_a
|
74
|
+
|
75
|
+
session = authorized_client.start_session
|
76
|
+
session.with_transaction(
|
77
|
+
read: { mode: :primary }
|
78
|
+
) do
|
79
|
+
collection.find({}, session: session).to_a
|
80
|
+
end
|
81
|
+
|
82
|
+
expect(subscriber.command_started_events('find').length).to eq(2)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when transaction is committed' do
|
87
|
+
it 'clears the cache' do
|
88
|
+
session = authorized_client.start_session
|
89
|
+
session.with_transaction do
|
90
|
+
collection.insert_one({ test: 1 }, session: session)
|
91
|
+
collection.insert_one({ test: 2 }, session: session)
|
92
|
+
|
93
|
+
expect(collection.find({}, session: session).to_a.length).to eq(2)
|
94
|
+
expect(collection.find({}, session: session).to_a.length).to eq(2)
|
95
|
+
|
96
|
+
# The driver caches the queries within the transaction
|
97
|
+
expect(subscriber.command_started_events('find').length).to eq(1)
|
98
|
+
session.commit_transaction
|
99
|
+
end
|
100
|
+
|
101
|
+
expect(collection.find.to_a.length).to eq(2)
|
102
|
+
|
103
|
+
# The driver clears the cache and runs the query again
|
104
|
+
expect(subscriber.command_started_events('find').length).to eq(2)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'when transaction is aborted' do
|
109
|
+
it 'clears the cache' do
|
110
|
+
session = authorized_client.start_session
|
111
|
+
session.with_transaction do
|
112
|
+
collection.insert_one({ test: 1 }, session: session)
|
113
|
+
collection.insert_one({ test: 2 }, session: session)
|
114
|
+
|
115
|
+
expect(collection.find({}, session: session).to_a.length).to eq(2)
|
116
|
+
expect(collection.find({}, session: session).to_a.length).to eq(2)
|
117
|
+
|
118
|
+
# The driver caches the queries within the transaction
|
119
|
+
expect(subscriber.command_started_events('find').length).to eq(1)
|
120
|
+
session.abort_transaction
|
121
|
+
end
|
122
|
+
|
123
|
+
expect(collection.find.to_a.length).to eq(0)
|
124
|
+
|
125
|
+
# The driver clears the cache and runs the query again
|
126
|
+
expect(subscriber.command_started_events('find').length).to eq(2)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'with low-level API' do
|
132
|
+
context 'when transaction is committed' do
|
133
|
+
it 'clears the cache' do
|
134
|
+
session = authorized_client.start_session
|
135
|
+
session.start_transaction
|
136
|
+
|
137
|
+
collection.insert_one({ test: 1 }, session: session)
|
138
|
+
collection.insert_one({ test: 2 }, session: session)
|
139
|
+
|
140
|
+
expect(collection.find({}, session: session).to_a.length).to eq(2)
|
141
|
+
expect(collection.find({}, session: session).to_a.length).to eq(2)
|
142
|
+
|
143
|
+
# The driver caches the queries within the transaction
|
144
|
+
expect(subscriber.command_started_events('find').length).to eq(1)
|
145
|
+
|
146
|
+
session.commit_transaction
|
147
|
+
|
148
|
+
expect(collection.find.to_a.length).to eq(2)
|
149
|
+
|
150
|
+
# The driver clears the cache and runs the query again
|
151
|
+
expect(subscriber.command_started_events('find').length).to eq(2)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when transaction is aborted' do
|
156
|
+
it 'clears the cache' do
|
157
|
+
session = authorized_client.start_session
|
158
|
+
session.start_transaction
|
159
|
+
|
160
|
+
collection.insert_one({ test: 1 }, session: session)
|
161
|
+
collection.insert_one({ test: 2 }, session: session)
|
162
|
+
|
163
|
+
expect(collection.find({}, session: session).to_a.length).to eq(2)
|
164
|
+
expect(collection.find({}, session: session).to_a.length).to eq(2)
|
165
|
+
|
166
|
+
# The driver caches the queries within the transaction
|
167
|
+
expect(subscriber.command_started_events('find').length).to eq(1)
|
168
|
+
|
169
|
+
session.abort_transaction
|
170
|
+
|
171
|
+
expect(collection.find.to_a.length).to eq(0)
|
172
|
+
|
173
|
+
# The driver clears the cache and runs the query again
|
174
|
+
expect(subscriber.command_started_events('find').length).to eq(2)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -197,6 +197,74 @@ describe 'SDAM error handling' do
|
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
|
+
describe 'when there is an error during connection establishment' do
|
201
|
+
require_topology :single
|
202
|
+
|
203
|
+
# The push monitor creates sockets unpredictably and interferes with this
|
204
|
+
# test.
|
205
|
+
max_server_version '4.2'
|
206
|
+
|
207
|
+
# When TLS is used there are two socket classes and we can't simply
|
208
|
+
# mock the base Socket class.
|
209
|
+
require_no_tls
|
210
|
+
|
211
|
+
{
|
212
|
+
SystemCallError => Mongo::Error::SocketError,
|
213
|
+
Errno::ETIMEDOUT => Mongo::Error::SocketTimeoutError,
|
214
|
+
}.each do |raw_error_cls, mapped_error_cls|
|
215
|
+
context raw_error_cls.name do
|
216
|
+
let(:socket) do
|
217
|
+
double('mock socket').tap do |socket|
|
218
|
+
allow(socket).to receive(:set_encoding)
|
219
|
+
allow(socket).to receive(:setsockopt)
|
220
|
+
allow(socket).to receive(:getsockopt)
|
221
|
+
allow(socket).to receive(:connect)
|
222
|
+
allow(socket).to receive(:close)
|
223
|
+
socket.should receive(:write).and_raise(raw_error_cls, 'mocked failure')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'marks server unknown' do
|
228
|
+
server = client.cluster.next_primary
|
229
|
+
client.cluster.servers.map(&:disconnect!)
|
230
|
+
|
231
|
+
RSpec::Mocks.with_temporary_scope do
|
232
|
+
|
233
|
+
Socket.should receive(:new).with(any_args).ordered.once.and_return(socket)
|
234
|
+
|
235
|
+
lambda do
|
236
|
+
client.command(ping: 1)
|
237
|
+
end.should raise_error(mapped_error_cls, /mocked failure/)
|
238
|
+
|
239
|
+
server.should be_unknown
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'recovers' do
|
244
|
+
server = client.cluster.next_primary
|
245
|
+
# If we do not kill the monitor, the client will recover automatically.
|
246
|
+
|
247
|
+
RSpec::Mocks.with_temporary_scope do
|
248
|
+
|
249
|
+
Socket.should receive(:new).with(any_args).ordered.once.and_return(socket)
|
250
|
+
Socket.should receive(:new).with(any_args).ordered.once.and_call_original
|
251
|
+
|
252
|
+
lambda do
|
253
|
+
client.command(ping: 1)
|
254
|
+
end.should raise_error(mapped_error_cls, /mocked failure/)
|
255
|
+
|
256
|
+
client.command(ping: 1)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
after do
|
263
|
+
# Since we stopped monitoring on the client, close it.
|
264
|
+
ClientRegistry.instance.close_all_clients
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
200
268
|
describe 'when there is an error on monitoring connection' do
|
201
269
|
clean_slate_for_all
|
202
270
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Server selection' do
|
4
|
+
context 'replica set' do
|
5
|
+
require_topology :replica_set
|
6
|
+
# 2.6 server does not provide replSetGetConfig and hence we cannot add
|
7
|
+
# the tags to the members.
|
8
|
+
min_server_version '3.0'
|
9
|
+
|
10
|
+
context 'when mixed case tag names are used' do
|
11
|
+
# For simplicity this test assumes our Evergreen configuration:
|
12
|
+
# nodes are started from port 27017 onwards and there are more than
|
13
|
+
# one of them.
|
14
|
+
|
15
|
+
let(:desired_index) do
|
16
|
+
if authorized_client.cluster.next_primary.address.port == 27017
|
17
|
+
1
|
18
|
+
else
|
19
|
+
0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:client) do
|
24
|
+
new_local_client(SpecConfig.instance.addresses,
|
25
|
+
SpecConfig.instance.authorized_test_options.merge(
|
26
|
+
server_selection_timeout: 4,
|
27
|
+
read: {mode: :secondary, tag_sets: [nodeIndex: desired_index.to_s]},
|
28
|
+
))
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'selects the server' do
|
32
|
+
client['nonexistent'].count.should == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -76,6 +76,37 @@ describe 'SRV Monitoring' do
|
|
76
76
|
require 'support/dns'
|
77
77
|
end
|
78
78
|
|
79
|
+
around do |example|
|
80
|
+
# Speed up the tests by listening on the fake ports we are using.
|
81
|
+
done = false
|
82
|
+
|
83
|
+
servers = []
|
84
|
+
threads = [27998, 27999].map do |port|
|
85
|
+
Thread.new do
|
86
|
+
server = TCPServer.open(port)
|
87
|
+
servers << server
|
88
|
+
begin
|
89
|
+
loop do
|
90
|
+
break if done
|
91
|
+
server.accept.close rescue nil
|
92
|
+
end
|
93
|
+
ensure
|
94
|
+
server.close
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
begin
|
100
|
+
example.run
|
101
|
+
ensure
|
102
|
+
done = true
|
103
|
+
servers.map(&:close)
|
104
|
+
|
105
|
+
threads.map(&:kill)
|
106
|
+
threads.map(&:join)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
79
110
|
let(:uri) do
|
80
111
|
"mongodb+srv://test-fake.test.build.10gen.cc/?tls=#{SpecConfig.instance.ssl?}&tlsInsecure=true"
|
81
112
|
end
|
@@ -88,11 +119,15 @@ describe 'SRV Monitoring' do
|
|
88
119
|
new_local_client(uri,
|
89
120
|
SpecConfig.instance.ssl_options.merge(
|
90
121
|
server_selection_timeout: 3.16,
|
91
|
-
|
122
|
+
socket_timeout: 8.11,
|
92
123
|
connect_timeout: 8.12,
|
93
124
|
resolv_options: {
|
94
|
-
|
95
|
-
|
125
|
+
# Using localhost instead of 127.0.0.1 here causes Ruby's resolv
|
126
|
+
# client to drop responses.
|
127
|
+
nameserver: '127.0.0.1',
|
128
|
+
# TODO figure out why the address & port here need to be given
|
129
|
+
# twice - if given once, DNS resolution fails.
|
130
|
+
nameserver_port: [['127.0.0.1', 5300], ['127.0.0.1', 5300]],
|
96
131
|
},
|
97
132
|
logger: logger,
|
98
133
|
),
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'SRV lookup' do
|
4
|
+
context 'end to end' do
|
5
|
+
|
6
|
+
# JRuby apparently does not implement non-blocking UDP I/O which is used
|
7
|
+
# by RubyDNS:
|
8
|
+
# NotImplementedError: recvmsg_nonblock is not implemented
|
9
|
+
fails_on_jruby
|
10
|
+
|
11
|
+
before(:all) do
|
12
|
+
require 'support/dns'
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:uri) do
|
16
|
+
"mongodb+srv://test-fake.test.build.10gen.cc/?tls=#{SpecConfig.instance.ssl?}&tlsInsecure=true"
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:client) do
|
20
|
+
new_local_client(uri,
|
21
|
+
SpecConfig.instance.ssl_options.merge(
|
22
|
+
server_selection_timeout: 3.16,
|
23
|
+
timeout: 4.11,
|
24
|
+
connect_timeout: 4.12,
|
25
|
+
resolv_options: {
|
26
|
+
nameserver: 'localhost',
|
27
|
+
nameserver_port: [['localhost', 5300], ['127.0.0.1', 5300]],
|
28
|
+
},
|
29
|
+
),
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'DNS resolver not responding' do
|
34
|
+
it 'fails to create client' do
|
35
|
+
lambda do
|
36
|
+
client
|
37
|
+
end.should raise_error(Mongo::Error::NoSRVRecords, /The DNS query returned no SRV records for 'test-fake.test.build.10gen.cc'/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'times out in connect_timeout' do
|
41
|
+
start_time = Time.now
|
42
|
+
|
43
|
+
lambda do
|
44
|
+
client
|
45
|
+
end.should raise_error(Mongo::Error::NoSRVRecords)
|
46
|
+
|
47
|
+
elapsed_time = Time.now - start_time
|
48
|
+
elapsed_time.should > 4
|
49
|
+
# The number of queries performed depends on local DNS search suffixes,
|
50
|
+
# therefore we cannot reliably assert how long it would take for this
|
51
|
+
# resolution to time out.
|
52
|
+
#elapsed_time.should < 8
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/lite_spec_helper.rb
CHANGED
@@ -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(
|
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'
|