mongo 2.5.0 → 2.5.1
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 +0 -0
- data/README.md +2 -0
- data/Rakefile +4 -1
- data/lib/mongo/address.rb +2 -1
- data/lib/mongo/client.rb +6 -51
- data/lib/mongo/cluster.rb +34 -4
- data/lib/mongo/cluster/reapers/socket_reaper.rb +1 -1
- data/lib/mongo/cluster/topology/replica_set.rb +3 -1
- data/lib/mongo/collection.rb +6 -6
- data/lib/mongo/collection/view.rb +2 -4
- data/lib/mongo/cursor.rb +9 -4
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/operation/uses_command_op_msg.rb +1 -1
- data/lib/mongo/server.rb +3 -0
- data/lib/mongo/server/description.rb +1 -1
- data/lib/mongo/server/description/features.rb +18 -12
- data/lib/mongo/server_selector/selectable.rb +5 -1
- data/lib/mongo/session.rb +38 -43
- data/lib/mongo/session/session_pool.rb +12 -30
- data/lib/mongo/socket.rb +24 -0
- data/lib/mongo/socket/tcp.rb +0 -1
- data/lib/mongo/uri.rb +26 -5
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/address_spec.rb +37 -2
- data/spec/mongo/bulk_write_spec.rb +4 -10
- data/spec/mongo/change_stream_examples_spec.rb +40 -0
- data/spec/mongo/client_spec.rb +47 -12
- data/spec/mongo/cluster/topology/replica_set_spec.rb +2 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +2 -8
- data/spec/mongo/collection/view/change_stream_spec.rb +1 -5
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -8
- data/spec/mongo/collection/view/readable_spec.rb +1 -1
- data/spec/mongo/collection_spec.rb +11 -29
- data/spec/mongo/crud_spec.rb +6 -2
- data/spec/mongo/cursor_spec.rb +84 -1
- data/spec/mongo/database_spec.rb +2 -8
- data/spec/mongo/dns_seedlist_discovery_spec.rb +67 -63
- data/spec/mongo/max_staleness_spec.rb +1 -0
- data/spec/mongo/retryable_writes_spec.rb +7 -9
- data/spec/mongo/sdam_spec.rb +42 -24
- data/spec/mongo/server/description/features_spec.rb +3 -3
- data/spec/mongo/server_selection_spec.rb +2 -0
- data/spec/mongo/server_selector_spec.rb +2 -0
- data/spec/mongo/session/session_pool_spec.rb +16 -22
- data/spec/mongo/session_spec.rb +13 -8
- data/spec/mongo/uri/srv_protocol_spec.rb +481 -478
- data/spec/mongo/uri_spec.rb +1 -1
- data/spec/spec_helper.rb +11 -63
- data/spec/support/authorization.rb +35 -1
- data/spec/support/connection_string_tests/invalid-uris.yml +27 -11
- data/spec/support/event_subscriber.rb +66 -0
- data/spec/support/sdam/rs/compatible.yml +41 -0
- data/spec/support/sdam/rs/discover_arbiters.yml +3 -1
- data/spec/support/sdam/rs/discover_passives.yml +6 -2
- data/spec/support/sdam/rs/discover_primary.yml +3 -1
- data/spec/support/sdam/rs/discover_secondary.yml +3 -1
- data/spec/support/sdam/rs/discovery.yml +12 -4
- data/spec/support/sdam/rs/equal_electionids.yml +6 -2
- data/spec/support/sdam/rs/ghost_discovered.yml +3 -1
- data/spec/support/sdam/rs/hosts_differ_from_seeds.yml +3 -1
- data/spec/support/sdam/rs/ls_timeout.yml +169 -14
- data/spec/support/sdam/rs/member_reconfig.yml +6 -2
- data/spec/support/sdam/rs/member_standalone.yml +6 -2
- data/spec/support/sdam/rs/new_primary.yml +6 -2
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +9 -3
- data/spec/support/sdam/rs/new_primary_new_setversion.yml +9 -3
- data/spec/support/sdam/rs/new_primary_wrong_set_name.yml +6 -2
- data/spec/support/sdam/rs/non_rs_member.yml +3 -2
- data/spec/support/sdam/rs/normalize_case.yml +3 -1
- data/spec/support/sdam/rs/null_election_id.yml +12 -4
- data/spec/support/sdam/rs/primary_becomes_standalone.yml +6 -4
- data/spec/support/sdam/rs/primary_changes_set_name.yml +6 -2
- data/spec/support/sdam/rs/primary_disconnect.yml +3 -1
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +15 -5
- data/spec/support/sdam/rs/primary_disconnect_setversion.yml +15 -5
- data/spec/support/sdam/rs/primary_hint_from_secondary_with_mismatched_me.yml +6 -2
- data/spec/support/sdam/rs/primary_mismatched_me.yml +26 -37
- data/spec/support/sdam/rs/primary_reports_new_member.yml +12 -4
- data/spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml +6 -2
- data/spec/support/sdam/rs/primary_wrong_set_name.yml +3 -1
- data/spec/support/sdam/rs/response_from_removed.yml +6 -2
- data/spec/support/sdam/rs/rsother_discovered.yml +6 -2
- data/spec/support/sdam/rs/sec_not_auth.yml +6 -2
- data/spec/support/sdam/rs/secondary_mismatched_me.yml +26 -37
- data/spec/support/sdam/rs/secondary_wrong_set_name.yml +3 -1
- data/spec/support/sdam/rs/secondary_wrong_set_name_with_primary.yml +6 -2
- data/spec/support/sdam/rs/setversion_without_electionid.yml +6 -2
- data/spec/support/sdam/rs/stepdown_change_set_name.yml +6 -2
- data/spec/support/sdam/rs/too_new.yml +41 -0
- data/spec/support/sdam/rs/too_old.yml +39 -0
- data/spec/support/sdam/rs/unexpected_mongos.yml +3 -1
- data/spec/support/sdam/rs/use_setversion_without_electionid.yml +9 -3
- data/spec/support/sdam/rs/wrong_set_name.yml +3 -1
- data/spec/support/server_discovery_and_monitoring.rb +13 -0
- data/spec/support/shared/session.rb +10 -30
- metadata +10 -2
- metadata.gz.sig +0 -0
@@ -532,6 +532,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
532
532
|
allow(d).to receive(:replica_set_member?).and_return(true)
|
533
533
|
allow(d).to receive(:replica_set_name).and_return('testing')
|
534
534
|
allow(d).to receive(:lists_server?).and_return(true)
|
535
|
+
allow(d).to receive(:servers).and_return([double('server')])
|
535
536
|
end
|
536
537
|
end
|
537
538
|
|
@@ -549,6 +550,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
549
550
|
allow(d).to receive(:replica_set_name).and_return('testing')
|
550
551
|
allow(d).to receive(:is_server?).and_return(false)
|
551
552
|
allow(d).to receive(:lists_server?).and_return(false)
|
553
|
+
allow(d).to receive(:servers).and_return([double('server')])
|
552
554
|
end
|
553
555
|
end
|
554
556
|
|
@@ -231,26 +231,20 @@ describe Mongo::Collection::View::Aggregation do
|
|
231
231
|
end
|
232
232
|
|
233
233
|
let(:client) do
|
234
|
-
|
235
|
-
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
236
|
-
end
|
234
|
+
subscribed_client
|
237
235
|
end
|
238
236
|
|
239
237
|
let(:session) do
|
240
238
|
client.start_session
|
241
239
|
end
|
242
240
|
|
243
|
-
let(:subscriber) do
|
244
|
-
EventSubscriber.new
|
245
|
-
end
|
246
|
-
|
247
241
|
let(:view) do
|
248
242
|
Mongo::Collection::View.new(client[TEST_COLL], selector, view_options)
|
249
243
|
end
|
250
244
|
|
251
245
|
let(:command) do
|
252
246
|
aggregation.explain
|
253
|
-
|
247
|
+
EventSubscriber.started_events.find { |c| c.command_name == 'aggregate'}.command
|
254
248
|
end
|
255
249
|
|
256
250
|
it 'sends the session id' do
|
@@ -314,11 +314,7 @@ describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
|
|
314
314
|
context 'when a session from another client is provided' do
|
315
315
|
|
316
316
|
let(:session) do
|
317
|
-
|
318
|
-
end
|
319
|
-
|
320
|
-
let(:client) do
|
321
|
-
authorized_client.with(read: { mode: :secondary })
|
317
|
+
authorized_client_with_retry_writes.start_session
|
322
318
|
end
|
323
319
|
|
324
320
|
let(:operation_result) do
|
@@ -240,17 +240,11 @@ describe Mongo::Collection::View::MapReduce do
|
|
240
240
|
end
|
241
241
|
|
242
242
|
let(:client) do
|
243
|
-
|
244
|
-
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
let(:subscriber) do
|
249
|
-
EventSubscriber.new
|
243
|
+
subscribed_client
|
250
244
|
end
|
251
245
|
|
252
246
|
let(:find_command) do
|
253
|
-
|
247
|
+
EventSubscriber.started_events[-1].command
|
254
248
|
end
|
255
249
|
|
256
250
|
before do
|
@@ -191,7 +191,7 @@ describe Mongo::Collection::View::Readable do
|
|
191
191
|
|
192
192
|
let(:command) do
|
193
193
|
operation
|
194
|
-
|
194
|
+
EventSubscriber.started_events.find { |cmd| cmd.command_name == 'mapreduce' }.command
|
195
195
|
end
|
196
196
|
|
197
197
|
it_behaves_like 'an operation supporting causally consistent reads'
|
@@ -900,26 +900,20 @@ describe Mongo::Collection do
|
|
900
900
|
end
|
901
901
|
|
902
902
|
let(:client) do
|
903
|
-
|
904
|
-
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
905
|
-
end
|
903
|
+
subscribed_client
|
906
904
|
end
|
907
905
|
|
908
906
|
let(:session) do
|
909
907
|
client.start_session
|
910
908
|
end
|
911
909
|
|
912
|
-
let(:subscriber) do
|
913
|
-
EventSubscriber.new
|
914
|
-
end
|
915
|
-
|
916
910
|
let(:view) do
|
917
911
|
Mongo::Collection::View.new(client[TEST_COLL], selector, view_options)
|
918
912
|
end
|
919
913
|
|
920
914
|
let(:command) do
|
921
915
|
client[TEST_COLL].find({}, session: session).explain
|
922
|
-
|
916
|
+
EventSubscriber.started_events.find { |c| c.command_name == :explain }.command
|
923
917
|
end
|
924
918
|
|
925
919
|
it 'sends the session id' do
|
@@ -935,7 +929,7 @@ describe Mongo::Collection do
|
|
935
929
|
|
936
930
|
let(:command) do
|
937
931
|
operation
|
938
|
-
|
932
|
+
EventSubscriber.started_events.find { |cmd| cmd.command_name == 'find' }.command
|
939
933
|
end
|
940
934
|
|
941
935
|
it_behaves_like 'an operation supporting causally consistent reads'
|
@@ -1205,13 +1199,7 @@ describe Mongo::Collection do
|
|
1205
1199
|
context 'when the documents are sent with OP_MSG', if: op_msg_enabled? do
|
1206
1200
|
|
1207
1201
|
let(:client) do
|
1208
|
-
|
1209
|
-
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
1210
|
-
end
|
1211
|
-
end
|
1212
|
-
|
1213
|
-
let(:subscriber) do
|
1214
|
-
EventSubscriber.new
|
1202
|
+
subscribed_client
|
1215
1203
|
end
|
1216
1204
|
|
1217
1205
|
let(:documents) do
|
@@ -1227,7 +1215,7 @@ describe Mongo::Collection do
|
|
1227
1215
|
end
|
1228
1216
|
|
1229
1217
|
let(:insert_events) do
|
1230
|
-
|
1218
|
+
EventSubscriber.started_events.select { |e| e.command_name == :insert }
|
1231
1219
|
end
|
1232
1220
|
|
1233
1221
|
it 'sends the documents in one OP_MSG' do
|
@@ -1574,7 +1562,7 @@ describe Mongo::Collection do
|
|
1574
1562
|
|
1575
1563
|
let(:command) do
|
1576
1564
|
operation
|
1577
|
-
|
1565
|
+
EventSubscriber.started_events.find { |cmd| cmd.command_name == 'aggregate' }.command
|
1578
1566
|
end
|
1579
1567
|
|
1580
1568
|
it_behaves_like 'an operation supporting causally consistent reads'
|
@@ -1738,7 +1726,7 @@ describe Mongo::Collection do
|
|
1738
1726
|
|
1739
1727
|
let(:command) do
|
1740
1728
|
operation
|
1741
|
-
|
1729
|
+
EventSubscriber.started_events.find { |cmd| cmd.command_name == :count }.command
|
1742
1730
|
end
|
1743
1731
|
|
1744
1732
|
it_behaves_like 'an operation supporting causally consistent reads'
|
@@ -1852,7 +1840,7 @@ describe Mongo::Collection do
|
|
1852
1840
|
|
1853
1841
|
let(:command) do
|
1854
1842
|
operation
|
1855
|
-
|
1843
|
+
EventSubscriber.started_events.find { |cmd| cmd.command_name == :distinct }.command
|
1856
1844
|
end
|
1857
1845
|
|
1858
1846
|
it_behaves_like 'an operation supporting causally consistent reads'
|
@@ -2344,7 +2332,7 @@ describe Mongo::Collection do
|
|
2344
2332
|
|
2345
2333
|
let(:command) do
|
2346
2334
|
operation
|
2347
|
-
|
2335
|
+
EventSubscriber.started_events.find { |cmd| cmd.command_name == :parallelCollectionScan }.command
|
2348
2336
|
end
|
2349
2337
|
|
2350
2338
|
it_behaves_like 'an operation supporting causally consistent reads'
|
@@ -3486,13 +3474,7 @@ describe Mongo::Collection do
|
|
3486
3474
|
context 'when the documents are sent with OP_MSG', if: op_msg_enabled? do
|
3487
3475
|
|
3488
3476
|
let(:client) do
|
3489
|
-
|
3490
|
-
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
3491
|
-
end
|
3492
|
-
end
|
3493
|
-
|
3494
|
-
let(:subscriber) do
|
3495
|
-
EventSubscriber.new
|
3477
|
+
subscribed_client
|
3496
3478
|
end
|
3497
3479
|
|
3498
3480
|
let(:documents) do
|
@@ -3509,7 +3491,7 @@ describe Mongo::Collection do
|
|
3509
3491
|
end
|
3510
3492
|
|
3511
3493
|
let(:update_events) do
|
3512
|
-
|
3494
|
+
EventSubscriber.started_events.select { |e| e.command_name == :update }
|
3513
3495
|
end
|
3514
3496
|
|
3515
3497
|
it 'sends the documents in one OP_MSG' do
|
data/spec/mongo/crud_spec.rb
CHANGED
@@ -10,6 +10,12 @@ describe 'CRUD' do
|
|
10
10
|
|
11
11
|
spec.tests.each do |test|
|
12
12
|
|
13
|
+
around do |example|
|
14
|
+
if spec.server_version_satisfied?(authorized_client)
|
15
|
+
example.run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
13
19
|
context(test.description) do
|
14
20
|
|
15
21
|
before(:each) do
|
@@ -25,12 +31,10 @@ describe 'CRUD' do
|
|
25
31
|
end
|
26
32
|
|
27
33
|
it 'returns the correct result' do
|
28
|
-
skip 'Test cannot be run on this server version' unless spec.server_version_satisfied?(authorized_client)
|
29
34
|
expect(results).to match_operation_result(test)
|
30
35
|
end
|
31
36
|
|
32
37
|
it 'has the correct data in the collection', if: test.outcome_collection_data do
|
33
|
-
skip 'Test cannot be run on this server version' unless spec.server_version_satisfied?(authorized_client)
|
34
38
|
results
|
35
39
|
expect(authorized_collection.find.to_a).to match_collection_data(test)
|
36
40
|
end
|
data/spec/mongo/cursor_spec.rb
CHANGED
@@ -301,10 +301,14 @@ describe Mongo::Cursor do
|
|
301
301
|
authorized_collection.find({}, batch_size: 2)
|
302
302
|
end
|
303
303
|
|
304
|
+
let(:cursor) do
|
305
|
+
view.instance_variable_get(:@cursor)
|
306
|
+
end
|
307
|
+
|
304
308
|
let!(:cursor_id) do
|
305
309
|
enum.next
|
306
310
|
enum.next
|
307
|
-
|
311
|
+
cursor.id
|
308
312
|
end
|
309
313
|
|
310
314
|
let(:enum) do
|
@@ -322,6 +326,85 @@ describe Mongo::Cursor do
|
|
322
326
|
end
|
323
327
|
end
|
324
328
|
|
329
|
+
context 'when an implicit session is used', if: sessions_enabled? do
|
330
|
+
|
331
|
+
let(:collection) do
|
332
|
+
subscribed_client[TEST_COLL]
|
333
|
+
end
|
334
|
+
|
335
|
+
before do
|
336
|
+
collection.insert_many(documents)
|
337
|
+
end
|
338
|
+
|
339
|
+
after do
|
340
|
+
collection.delete_many
|
341
|
+
end
|
342
|
+
|
343
|
+
let(:cursor) do
|
344
|
+
view.instance_variable_get(:@cursor)
|
345
|
+
end
|
346
|
+
|
347
|
+
let(:enum) do
|
348
|
+
view.to_enum
|
349
|
+
end
|
350
|
+
|
351
|
+
let(:session_pool_ids) do
|
352
|
+
queue = view.client.cluster.session_pool.instance_variable_get(:@queue)
|
353
|
+
queue.collect { |s| s.session_id }
|
354
|
+
end
|
355
|
+
|
356
|
+
let(:find_events) do
|
357
|
+
EventSubscriber.started_events.select { |e| e.command_name == "find" }
|
358
|
+
end
|
359
|
+
|
360
|
+
context 'when all results are retrieved in the first response' do
|
361
|
+
|
362
|
+
let(:documents) do
|
363
|
+
(1..2).map{ |i| { field: "test#{i}" }}
|
364
|
+
end
|
365
|
+
|
366
|
+
let(:view) do
|
367
|
+
collection.find
|
368
|
+
end
|
369
|
+
|
370
|
+
it 'returns the session to the cluster session pool' do
|
371
|
+
1.times { enum.next }
|
372
|
+
expect(find_events.collect { |event| event.command['lsid'] }.uniq.size).to eq(1)
|
373
|
+
expect(session_pool_ids).to include(find_events.collect { |event| event.command['lsid'] }.uniq.first)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
context 'when a getmore is needed to retrieve all results', if: sessions_enabled? && !sharded? do
|
378
|
+
|
379
|
+
let(:documents) do
|
380
|
+
(1..4).map{ |i| { field: "test#{i}" }}
|
381
|
+
end
|
382
|
+
|
383
|
+
let(:view) do
|
384
|
+
collection.find({}, batch_size: 2, limit: 4)
|
385
|
+
end
|
386
|
+
|
387
|
+
|
388
|
+
context 'when not all documents are iterated' do
|
389
|
+
|
390
|
+
it 'returns the session to the cluster session pool' do
|
391
|
+
3.times { enum.next }
|
392
|
+
expect(find_events.collect { |event| event.command['lsid'] }.uniq.size).to eq(1)
|
393
|
+
expect(session_pool_ids).to include(find_events.collect { |event| event.command['lsid'] }.uniq.first)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context 'when all documents are iterated' do
|
398
|
+
|
399
|
+
it 'returns the session to the cluster session pool' do
|
400
|
+
4.times { enum.next }
|
401
|
+
expect(find_events.collect { |event| event.command['lsid'] }.uniq.size).to eq(1)
|
402
|
+
expect(session_pool_ids).to include(find_events.collect { |event| event.command['lsid'] }.uniq.first)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
325
408
|
describe '#inspect' do
|
326
409
|
|
327
410
|
let(:view) do
|
data/spec/mongo/database_spec.rb
CHANGED
@@ -256,13 +256,7 @@ describe Mongo::Database do
|
|
256
256
|
end
|
257
257
|
|
258
258
|
let(:client) do
|
259
|
-
|
260
|
-
cl.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
let(:subscriber) do
|
265
|
-
EventSubscriber.new
|
259
|
+
subscribed_client
|
266
260
|
end
|
267
261
|
|
268
262
|
it_behaves_like 'an operation using a session'
|
@@ -270,7 +264,7 @@ describe Mongo::Database do
|
|
270
264
|
|
271
265
|
|
272
266
|
let(:full_command) do
|
273
|
-
|
267
|
+
EventSubscriber.started_events.find { |cmd| cmd.command_name == :ismaster }.command
|
274
268
|
end
|
275
269
|
|
276
270
|
it 'does not add a afterClusterTime field' do
|
@@ -1,92 +1,96 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'DNS Seedlist Discovery' do
|
4
|
-
include Mongo::ConnectionString
|
5
|
-
|
6
|
-
before(:all) do
|
7
|
-
|
8
|
-
module Mongo
|
9
|
-
class Server
|
10
|
-
# The constructor keeps the same API, but does not instantiate a
|
11
|
-
# monitor and run it.
|
12
|
-
alias :original_initialize :initialize
|
13
|
-
|
14
|
-
def initialize(address, cluster, monitoring, event_listeners, options = {})
|
15
|
-
@address = address
|
16
|
-
@cluster = cluster
|
17
|
-
@monitoring = monitoring
|
18
|
-
@options = options.freeze
|
19
|
-
@monitor = Monitor.new(address, event_listeners, options)
|
20
|
-
end
|
21
4
|
|
22
|
-
|
23
|
-
|
24
|
-
|
5
|
+
if test_connecting_externally?
|
6
|
+
|
7
|
+
include Mongo::ConnectionString
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
|
11
|
+
module Mongo
|
12
|
+
class Server
|
13
|
+
# The constructor keeps the same API, but does not instantiate a
|
14
|
+
# monitor and run it.
|
15
|
+
alias :original_initialize :initialize
|
25
16
|
|
26
|
-
|
27
|
-
|
17
|
+
def initialize(address, cluster, monitoring, event_listeners, options = {})
|
18
|
+
@address = address
|
19
|
+
@cluster = cluster
|
20
|
+
@monitoring = monitoring
|
21
|
+
@options = options.freeze
|
22
|
+
@monitor = Monitor.new(address, event_listeners, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Disconnect simply needs to return true since we have no monitor and
|
26
|
+
# no connection.
|
27
|
+
alias :original_disconnect! :disconnect!
|
28
|
+
|
29
|
+
def disconnect!;
|
30
|
+
true;
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
31
|
-
end
|
32
35
|
|
33
|
-
|
36
|
+
after(:all) do
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
module Mongo
|
39
|
+
class Server
|
40
|
+
alias :initialize :original_initialize
|
41
|
+
remove_method(:original_initialize)
|
39
42
|
|
40
|
-
|
41
|
-
|
43
|
+
alias :disconnect! :original_disconnect!
|
44
|
+
remove_method(:original_disconnect!)
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
|
-
end
|
45
48
|
|
46
|
-
|
49
|
+
DNS_SEEDLIST_DISCOVERY_TESTS.each do |file_name|
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
file = File.new(file_name)
|
52
|
+
spec = YAML.load(ERB.new(file.read).result)
|
53
|
+
file.close
|
51
54
|
|
52
|
-
|
55
|
+
test = Mongo::ConnectionString::Test.new(spec)
|
53
56
|
|
54
|
-
|
57
|
+
context(File.basename(file_name), if: test_connecting_externally?) do
|
55
58
|
|
56
|
-
|
59
|
+
context 'when the uri is invalid', if: test.raise_error? do
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
let(:valid_errors) do
|
62
|
+
[
|
63
|
+
Mongo::Error::InvalidTXTRecord,
|
64
|
+
Mongo::Error::NoSRVRecords,
|
65
|
+
Mongo::Error::InvalidURI,
|
66
|
+
Mongo::Error::MismatchedDomain,
|
67
|
+
]
|
68
|
+
end
|
66
69
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
let(:error) do
|
71
|
+
e = nil
|
72
|
+
begin; test.uri; rescue => ex; e = ex; end
|
73
|
+
e
|
74
|
+
end
|
72
75
|
|
73
|
-
|
74
|
-
|
76
|
+
it 'raises an error' do
|
77
|
+
expect(valid_errors).to include(error.class)
|
78
|
+
end
|
75
79
|
end
|
76
|
-
end
|
77
80
|
|
78
|
-
|
81
|
+
context 'when the uri is valid', unless: test.raise_error? do
|
79
82
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
+
it 'does not raise an exception' do
|
84
|
+
expect(test.uri).to be_a(Mongo::URI::SRVProtocol)
|
85
|
+
end
|
83
86
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
+
it 'creates a client with the correct hosts' do
|
88
|
+
expect(test.client).to have_hosts(test)
|
89
|
+
end
|
87
90
|
|
88
|
-
|
89
|
-
|
91
|
+
it 'creates a client with the correct options' do
|
92
|
+
expect(test.client).to match_options(test)
|
93
|
+
end
|
90
94
|
end
|
91
95
|
end
|
92
96
|
end
|