mongo 2.1.0.rc0 → 2.1.0
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 +5 -2
- data.tar.gz.sig +0 -0
- data/Rakefile +2 -2
- data/lib/mongo.rb +2 -1
- data/lib/mongo/address.rb +11 -5
- data/lib/mongo/address/ipv4.rb +6 -1
- data/lib/mongo/auth/cr/conversation.rb +1 -1
- data/lib/mongo/auth/ldap/conversation.rb +1 -1
- data/lib/mongo/auth/scram/conversation.rb +1 -1
- data/lib/mongo/auth/user/view.rb +2 -2
- data/lib/mongo/auth/x509/conversation.rb +1 -1
- data/lib/mongo/bulk_write.rb +12 -9
- data/lib/mongo/bulk_write/transformable.rb +20 -5
- data/lib/mongo/client.rb +11 -11
- data/lib/mongo/cluster.rb +2 -2
- data/lib/mongo/collection.rb +21 -8
- data/lib/mongo/collection/view.rb +1 -0
- data/lib/mongo/collection/view/aggregation.rb +11 -5
- data/lib/mongo/collection/view/iterable.rb +6 -2
- data/lib/mongo/collection/view/map_reduce.rb +39 -5
- data/lib/mongo/collection/view/readable.rb +35 -30
- data/lib/mongo/collection/view/writable.rb +26 -18
- data/lib/mongo/database.rb +12 -2
- data/lib/mongo/database/view.rb +4 -3
- data/lib/mongo/dbref.rb +4 -4
- data/lib/mongo/grid/fs_bucket.rb +8 -1
- data/lib/mongo/grid/stream/read.rb +1 -1
- data/lib/mongo/index.rb +5 -0
- data/lib/mongo/index/view.rb +2 -2
- data/lib/mongo/monitoring/command_log_subscriber.rb +9 -3
- data/lib/mongo/monitoring/event.rb +1 -0
- data/lib/mongo/monitoring/event/command_started.rb +2 -1
- data/lib/mongo/monitoring/event/command_succeeded.rb +6 -3
- data/lib/mongo/monitoring/event/secure.rb +58 -0
- data/lib/mongo/operation.rb +31 -1
- data/lib/mongo/operation/commands/collections_info.rb +2 -0
- data/lib/mongo/operation/commands/collections_info/result.rb +39 -0
- data/lib/mongo/operation/commands/list_indexes/result.rb +2 -1
- data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
- data/lib/mongo/operation/read/query.rb +2 -0
- data/lib/mongo/operation/read/query/result.rb +40 -0
- data/lib/mongo/operation/result.rb +13 -1
- data/lib/mongo/operation/write/bulk/delete.rb +2 -2
- data/lib/mongo/operation/write/bulk/update.rb +3 -3
- data/lib/mongo/operation/write/delete.rb +2 -2
- data/lib/mongo/operation/write/update.rb +9 -4
- data/lib/mongo/options.rb +1 -0
- data/lib/mongo/options/redacted.rb +156 -0
- data/lib/mongo/protocol/insert.rb +25 -6
- data/lib/mongo/protocol/query.rb +45 -31
- data/lib/mongo/protocol/reply.rb +29 -6
- data/lib/mongo/protocol/serializers.rb +1 -1
- data/lib/mongo/retryable.rb +83 -0
- data/lib/mongo/server.rb +16 -3
- data/lib/mongo/server/connectable.rb +21 -3
- data/lib/mongo/server/connection.rb +38 -4
- data/lib/mongo/server/connection_pool.rb +12 -0
- data/lib/mongo/server/connection_pool/queue.rb +15 -0
- data/lib/mongo/server/monitor/connection.rb +2 -2
- data/lib/mongo/server_selector.rb +5 -0
- data/lib/mongo/server_selector/selectable.rb +16 -9
- data/lib/mongo/socket.rb +6 -2
- data/lib/mongo/uri.rb +1 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +11 -11
- data/spec/mongo/bulk_write/unordered_combiner_spec.rb +10 -10
- data/spec/mongo/client_spec.rb +101 -18
- data/spec/mongo/collection_spec.rb +44 -0
- data/spec/mongo/connection_string_spec.rb +36 -58
- data/spec/mongo/database_spec.rb +20 -0
- data/spec/mongo/grid/fs_bucket_spec.rb +1 -1
- data/spec/mongo/grid/stream/write_spec.rb +2 -2
- data/spec/mongo/monitoring/event/command_started_spec.rb +26 -0
- data/spec/mongo/monitoring/event/command_succeeded_spec.rb +26 -0
- data/spec/mongo/monitoring/event/secure_spec.rb +57 -0
- data/spec/mongo/operation/commands/aggregate_spec.rb +0 -16
- data/spec/mongo/operation/commands/command_spec.rb +0 -18
- data/spec/mongo/operation/kill_cursors_spec.rb +0 -16
- data/spec/mongo/operation/read/get_more_spec.rb +0 -16
- data/spec/mongo/operation/read/query_spec.rb +19 -16
- data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -16
- data/spec/mongo/operation/write/bulk/update_spec.rb +6 -6
- data/spec/mongo/operation/write/command/delete_spec.rb +0 -16
- data/spec/mongo/operation/write/command/insert_spec.rb +0 -16
- data/spec/mongo/operation/write/command/update_spec.rb +0 -16
- data/spec/mongo/operation/write/delete_spec.rb +3 -3
- data/spec/mongo/operation/write/update_spec.rb +6 -6
- data/spec/mongo/options/redacted_spec.rb +350 -0
- data/spec/mongo/protocol/query_spec.rb +15 -1
- data/spec/mongo/retryable_spec.rb +147 -0
- data/spec/mongo/server/connection_pool/queue_spec.rb +16 -0
- data/spec/mongo/server/connection_pool_spec.rb +32 -0
- data/spec/mongo/server/connection_spec.rb +37 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +24 -59
- data/spec/mongo/server_selection_rtt_spec.rb +37 -57
- data/spec/mongo/server_selection_spec.rb +2 -0
- data/spec/mongo/server_selector/nearest_spec.rb +1 -0
- data/spec/mongo/server_selector/primary_preferred_spec.rb +1 -0
- data/spec/mongo/server_selector/primary_spec.rb +8 -2
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +1 -0
- data/spec/mongo/server_selector/secondary_spec.rb +1 -0
- data/spec/mongo/server_spec.rb +68 -1
- data/spec/mongo/socket/ssl_spec.rb +29 -5
- data/spec/mongo/uri_spec.rb +20 -20
- data/spec/support/crud.rb +7 -1
- data/spec/support/matchers.rb +1 -1
- data/spec/support/shared/server_selector.rb +58 -2
- metadata +20 -5
- metadata.gz.sig +0 -0
@@ -39,6 +39,7 @@ describe 'Server Selection' do
|
|
39
39
|
allow(s).to receive(:tags).and_return(server['tags'])
|
40
40
|
allow(s).to receive(:secondary?).and_return(server['type'] == 'RSSecondary')
|
41
41
|
allow(s).to receive(:primary?).and_return(server['type'] == 'RSPrimary')
|
42
|
+
allow(s).to receive(:connectable?).and_return(true)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
@@ -49,6 +50,7 @@ describe 'Server Selection' do
|
|
49
50
|
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS).tap do |s|
|
50
51
|
allow(s).to receive(:average_round_trip_time).and_return(server['avg_rtt_ms'])
|
51
52
|
allow(s).to receive(:tags).and_return(server['tags'])
|
53
|
+
allow(s).to receive(:connectable?).and_return(true)
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
@@ -9,6 +9,7 @@ describe Mongo::ServerSelector::Primary do
|
|
9
9
|
it_behaves_like 'a server selector mode' do
|
10
10
|
let(:slave_ok) { false }
|
11
11
|
end
|
12
|
+
it_behaves_like 'a server selector with sensitive data in its options'
|
12
13
|
|
13
14
|
describe '#tag_sets' do
|
14
15
|
|
@@ -20,10 +21,15 @@ describe Mongo::ServerSelector::Primary do
|
|
20
21
|
end
|
21
22
|
|
22
23
|
context 'tag sets provided' do
|
23
|
-
|
24
|
+
|
25
|
+
let(:tag_sets) do
|
26
|
+
[ tag_set ]
|
27
|
+
end
|
24
28
|
|
25
29
|
it 'raises an error' do
|
26
|
-
expect{
|
30
|
+
expect {
|
31
|
+
selector.tag_sets
|
32
|
+
}.to raise_error(Mongo::Error::InvalidServerPreference)
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
@@ -9,6 +9,7 @@ describe Mongo::ServerSelector::SecondaryPreferred do
|
|
9
9
|
it_behaves_like 'a server selector mode' do
|
10
10
|
let(:slave_ok) { true }
|
11
11
|
end
|
12
|
+
it_behaves_like 'a server selector with sensitive data in its options'
|
12
13
|
|
13
14
|
it_behaves_like 'a server selector accepting tag sets'
|
14
15
|
|
data/spec/mongo/server_spec.rb
CHANGED
@@ -24,6 +24,10 @@ describe Mongo::Server do
|
|
24
24
|
described_class.new(address, cluster, monitoring, listeners, TEST_OPTIONS)
|
25
25
|
end
|
26
26
|
|
27
|
+
after do
|
28
|
+
server.disconnect!
|
29
|
+
end
|
30
|
+
|
27
31
|
context 'when the other is not a server' do
|
28
32
|
|
29
33
|
let(:other) do
|
@@ -65,6 +69,43 @@ describe Mongo::Server do
|
|
65
69
|
end
|
66
70
|
end
|
67
71
|
|
72
|
+
describe '#connectable?' do
|
73
|
+
|
74
|
+
context 'when the server is connectable' do
|
75
|
+
|
76
|
+
let(:server) do
|
77
|
+
described_class.new(address, cluster, monitoring, listeners, TEST_OPTIONS)
|
78
|
+
end
|
79
|
+
|
80
|
+
after do
|
81
|
+
server.disconnect!
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns true' do
|
85
|
+
expect(server).to be_connectable
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when the server is not connectable' do
|
90
|
+
|
91
|
+
let(:bad_address) do
|
92
|
+
Mongo::Address.new('127.0.0.1:666')
|
93
|
+
end
|
94
|
+
|
95
|
+
let(:server) do
|
96
|
+
described_class.new(bad_address, cluster, monitoring, listeners, TEST_OPTIONS)
|
97
|
+
end
|
98
|
+
|
99
|
+
before do
|
100
|
+
server.disconnect!
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns false' do
|
104
|
+
expect(server).to_not be_connectable
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
68
109
|
describe '#context' do
|
69
110
|
|
70
111
|
let(:server) do
|
@@ -75,6 +116,10 @@ describe Mongo::Server do
|
|
75
116
|
server.context
|
76
117
|
end
|
77
118
|
|
119
|
+
after do
|
120
|
+
server.disconnect!
|
121
|
+
end
|
122
|
+
|
78
123
|
it 'returns a new server context' do
|
79
124
|
expect(context.server).to eq(server)
|
80
125
|
end
|
@@ -95,7 +140,17 @@ describe Mongo::Server do
|
|
95
140
|
describe '#initialize' do
|
96
141
|
|
97
142
|
let(:server) do
|
98
|
-
described_class.new(
|
143
|
+
described_class.new(
|
144
|
+
address,
|
145
|
+
cluster,
|
146
|
+
monitoring,
|
147
|
+
listeners,
|
148
|
+
TEST_OPTIONS.merge(:heartbeat_frequency => 5)
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
after do
|
153
|
+
server.disconnect!
|
99
154
|
end
|
100
155
|
|
101
156
|
it 'sets the address host' do
|
@@ -121,6 +176,10 @@ describe Mongo::Server do
|
|
121
176
|
server.pool
|
122
177
|
end
|
123
178
|
|
179
|
+
after do
|
180
|
+
server.disconnect!
|
181
|
+
end
|
182
|
+
|
124
183
|
it 'returns the connection pool for the server' do
|
125
184
|
expect(pool).to be_a(Mongo::Server::ConnectionPool)
|
126
185
|
end
|
@@ -132,6 +191,10 @@ describe Mongo::Server do
|
|
132
191
|
described_class.new(address, cluster, monitoring, listeners, TEST_OPTIONS)
|
133
192
|
end
|
134
193
|
|
194
|
+
after do
|
195
|
+
server.disconnect!
|
196
|
+
end
|
197
|
+
|
135
198
|
it 'forces a scan on the monitor' do
|
136
199
|
expect(server.scan!).to eq(server.description)
|
137
200
|
end
|
@@ -147,6 +210,10 @@ describe Mongo::Server do
|
|
147
210
|
expect(server.monitor).to receive(:restart!).and_call_original
|
148
211
|
end
|
149
212
|
|
213
|
+
after do
|
214
|
+
server.disconnect!
|
215
|
+
end
|
216
|
+
|
150
217
|
it 'restarts the monitor and returns true' do
|
151
218
|
expect(server.reconnect!).to be(true)
|
152
219
|
end
|
@@ -19,12 +19,36 @@ describe Mongo::Socket::SSL do
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
context 'when connecting the tcp socket is successful' do
|
24
|
+
|
25
|
+
before do
|
26
|
+
socket.connect!
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'connects to the server' do
|
30
|
+
expect(socket).to be_alive
|
31
|
+
end
|
24
32
|
end
|
25
33
|
|
26
|
-
|
27
|
-
|
34
|
+
context 'when connecting the tcp socket raises an exception' do
|
35
|
+
|
36
|
+
before do
|
37
|
+
tcp_socket = socket.instance_variable_get(:@tcp_socket)
|
38
|
+
allow(tcp_socket).to receive(:connect).and_raise(Mongo::Error::SocketTimeoutError)
|
39
|
+
end
|
40
|
+
|
41
|
+
let!(:result) do
|
42
|
+
begin
|
43
|
+
socket.connect!
|
44
|
+
rescue => e
|
45
|
+
e
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'raises an exception' do
|
50
|
+
expect(result).to be_a(Mongo::Error::SocketTimeoutError)
|
51
|
+
end
|
28
52
|
end
|
29
53
|
end
|
30
54
|
|
@@ -42,7 +66,7 @@ describe Mongo::Socket::SSL do
|
|
42
66
|
it 'raises an exception' do
|
43
67
|
expect {
|
44
68
|
socket.connect!
|
45
|
-
}.to
|
69
|
+
}.to raise_exception(OpenSSL::PKey::RSAError)
|
46
70
|
end
|
47
71
|
end
|
48
72
|
|
data/spec/mongo/uri_spec.rb
CHANGED
@@ -365,7 +365,7 @@ describe 'invalid uris' do
|
|
365
365
|
|
366
366
|
context 'numerical w value' do
|
367
367
|
let(:options) { 'w=1' }
|
368
|
-
let(:concern) {
|
368
|
+
let(:concern) { Mongo::Options::Redacted.new(:w => 1)}
|
369
369
|
|
370
370
|
it 'sets the write concern options' do
|
371
371
|
expect(uri.uri_options[:write]).to eq(concern)
|
@@ -374,7 +374,7 @@ describe 'invalid uris' do
|
|
374
374
|
|
375
375
|
context 'w=majority' do
|
376
376
|
let(:options) { 'w=majority' }
|
377
|
-
let(:concern) {
|
377
|
+
let(:concern) { Mongo::Options::Redacted.new(:w => :majority) }
|
378
378
|
|
379
379
|
it 'sets the write concern options' do
|
380
380
|
expect(uri.uri_options[:write]).to eq(concern)
|
@@ -383,7 +383,7 @@ describe 'invalid uris' do
|
|
383
383
|
|
384
384
|
context 'journal' do
|
385
385
|
let(:options) { 'journal=true' }
|
386
|
-
let(:concern) {
|
386
|
+
let(:concern) { Mongo::Options::Redacted.new(:j => true) }
|
387
387
|
|
388
388
|
it 'sets the write concern options' do
|
389
389
|
expect(uri.uri_options[:write]).to eq(concern)
|
@@ -392,7 +392,7 @@ describe 'invalid uris' do
|
|
392
392
|
|
393
393
|
context 'fsync' do
|
394
394
|
let(:options) { 'fsync=true' }
|
395
|
-
let(:concern) {
|
395
|
+
let(:concern) { Mongo::Options::Redacted.new(:fsync => true) }
|
396
396
|
|
397
397
|
it 'sets the write concern options' do
|
398
398
|
expect(uri.uri_options[:write]).to eq(concern)
|
@@ -402,7 +402,7 @@ describe 'invalid uris' do
|
|
402
402
|
context 'wtimeoutMS' do
|
403
403
|
let(:timeout) { 1234 }
|
404
404
|
let(:options) { "w=2&wtimeoutMS=#{timeout}" }
|
405
|
-
let(:concern) {
|
405
|
+
let(:concern) { Mongo::Options::Redacted.new(:w => 2, :timeout => timeout) }
|
406
406
|
|
407
407
|
it 'sets the write concern options' do
|
408
408
|
expect(uri.uri_options[:write]).to eq(concern)
|
@@ -415,7 +415,7 @@ describe 'invalid uris' do
|
|
415
415
|
|
416
416
|
context 'primary' do
|
417
417
|
let(:mode) { 'primary' }
|
418
|
-
let(:read) {
|
418
|
+
let(:read) { Mongo::Options::Redacted.new(:mode => :primary) }
|
419
419
|
|
420
420
|
it 'sets the read preference' do
|
421
421
|
expect(uri.uri_options[:read]).to eq(read)
|
@@ -424,7 +424,7 @@ describe 'invalid uris' do
|
|
424
424
|
|
425
425
|
context 'primaryPreferred' do
|
426
426
|
let(:mode) { 'primaryPreferred' }
|
427
|
-
let(:read) {
|
427
|
+
let(:read) { Mongo::Options::Redacted.new(:mode => :primary_preferred) }
|
428
428
|
|
429
429
|
it 'sets the read preference' do
|
430
430
|
expect(uri.uri_options[:read]).to eq(read)
|
@@ -433,7 +433,7 @@ describe 'invalid uris' do
|
|
433
433
|
|
434
434
|
context 'secondary' do
|
435
435
|
let(:mode) { 'secondary' }
|
436
|
-
let(:read) {
|
436
|
+
let(:read) { Mongo::Options::Redacted.new(:mode => :secondary) }
|
437
437
|
|
438
438
|
it 'sets the read preference' do
|
439
439
|
expect(uri.uri_options[:read]).to eq(read)
|
@@ -442,7 +442,7 @@ describe 'invalid uris' do
|
|
442
442
|
|
443
443
|
context 'secondaryPreferred' do
|
444
444
|
let(:mode) { 'secondaryPreferred' }
|
445
|
-
let(:read) {
|
445
|
+
let(:read) { Mongo::Options::Redacted.new(:mode => :secondary_preferred) }
|
446
446
|
|
447
447
|
it 'sets the read preference' do
|
448
448
|
expect(uri.uri_options[:read]).to eq(read)
|
@@ -451,7 +451,7 @@ describe 'invalid uris' do
|
|
451
451
|
|
452
452
|
context 'nearest' do
|
453
453
|
let(:mode) { 'nearest' }
|
454
|
-
let(:read) {
|
454
|
+
let(:read) { Mongo::Options::Redacted.new(:mode => :nearest) }
|
455
455
|
|
456
456
|
it 'sets the read preference' do
|
457
457
|
expect(uri.uri_options[:read]).to eq(read)
|
@@ -467,7 +467,7 @@ describe 'invalid uris' do
|
|
467
467
|
end
|
468
468
|
|
469
469
|
let(:read) do
|
470
|
-
|
470
|
+
Mongo::Options::Redacted.new(:tag_sets => [{ 'dc' => 'ny', 'rack' => '1' }])
|
471
471
|
end
|
472
472
|
|
473
473
|
it 'sets the read preference tag set' do
|
@@ -481,7 +481,7 @@ describe 'invalid uris' do
|
|
481
481
|
end
|
482
482
|
|
483
483
|
let(:read) do
|
484
|
-
|
484
|
+
Mongo::Options::Redacted.new(:tag_sets => [{ 'dc' => 'ny' }, { 'dc' => 'bos' }])
|
485
485
|
end
|
486
486
|
|
487
487
|
it 'sets the read preference tag sets' do
|
@@ -536,7 +536,7 @@ describe 'invalid uris' do
|
|
536
536
|
|
537
537
|
context 'regular db' do
|
538
538
|
let(:source) { 'foo' }
|
539
|
-
let(:auth) {
|
539
|
+
let(:auth) { Mongo::Options::Redacted.new(:source => 'foo') }
|
540
540
|
|
541
541
|
it 'sets the auth source to the database' do
|
542
542
|
expect(uri.uri_options[:auth]).to eq(auth)
|
@@ -545,7 +545,7 @@ describe 'invalid uris' do
|
|
545
545
|
|
546
546
|
context '$external' do
|
547
547
|
let(:source) { '$external' }
|
548
|
-
let(:auth) {
|
548
|
+
let(:auth) { Mongo::Options::Redacted.new(:source => :external) }
|
549
549
|
|
550
550
|
it 'sets the auth source to :external' do
|
551
551
|
expect(uri.uri_options[:auth]).to eq(auth)
|
@@ -562,7 +562,7 @@ describe 'invalid uris' do
|
|
562
562
|
|
563
563
|
let(:service_name) { 'foo' }
|
564
564
|
let(:auth) do
|
565
|
-
|
565
|
+
Mongo::Options::Redacted.new(auth_mech_properties: { service_name: service_name })
|
566
566
|
end
|
567
567
|
|
568
568
|
it 'sets the auth mechanism properties' do
|
@@ -577,7 +577,7 @@ describe 'invalid uris' do
|
|
577
577
|
|
578
578
|
let(:canonicalize_host_name) { 'true' }
|
579
579
|
let(:auth) do
|
580
|
-
|
580
|
+
Mongo::Options::Redacted.new(auth_mech_properties: { canonicalize_host_name: true })
|
581
581
|
end
|
582
582
|
|
583
583
|
it 'sets the auth mechanism properties' do
|
@@ -592,7 +592,7 @@ describe 'invalid uris' do
|
|
592
592
|
|
593
593
|
let(:service_realm) { 'dumdum' }
|
594
594
|
let(:auth) do
|
595
|
-
|
595
|
+
Mongo::Options::Redacted.new(auth_mech_properties: { service_realm: service_realm })
|
596
596
|
end
|
597
597
|
|
598
598
|
it 'sets the auth mechanism properties' do
|
@@ -612,9 +612,9 @@ describe 'invalid uris' do
|
|
612
612
|
let(:service_realm) { 'dumdum' }
|
613
613
|
|
614
614
|
let(:auth) do
|
615
|
-
|
616
|
-
|
617
|
-
|
615
|
+
Mongo::Options::Redacted.new(auth_mech_properties: { service_name: service_name,
|
616
|
+
canonicalize_host_name: true,
|
617
|
+
service_realm: service_realm })
|
618
618
|
end
|
619
619
|
|
620
620
|
it 'sets the auth mechanism properties' do
|
data/spec/support/crud.rb
CHANGED
@@ -144,7 +144,13 @@ module Mongo
|
|
144
144
|
#
|
145
145
|
# @since 2.0.0
|
146
146
|
def compare_collection_data
|
147
|
-
actual_collection_data
|
147
|
+
if actual_collection_data.nil?
|
148
|
+
outcome_collection_data.nil?
|
149
|
+
else
|
150
|
+
actual_collection_data.all? do |doc|
|
151
|
+
outcome_collection_data.include?(doc)
|
152
|
+
end
|
153
|
+
end
|
148
154
|
end
|
149
155
|
|
150
156
|
# Whether this test requires server version >= 2.6 for its results to match
|
data/spec/support/matchers.rb
CHANGED
@@ -12,7 +12,7 @@ def server(mode, options = {})
|
|
12
12
|
|
13
13
|
listeners = Mongo::Event::Listeners.new
|
14
14
|
monitoring = Mongo::Monitoring.new
|
15
|
-
address = Mongo::Address.new(
|
15
|
+
address = Mongo::Address.new(DEFAULT_ADDRESS)
|
16
16
|
|
17
17
|
server = Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
18
18
|
description = Mongo::Server::Description.new(address, ismaster, average_round_trip_time)
|
@@ -32,7 +32,46 @@ shared_context 'server selector' do
|
|
32
32
|
end
|
33
33
|
let(:primary) { server(:primary) }
|
34
34
|
let(:secondary) { server(:secondary) }
|
35
|
-
let(:
|
35
|
+
let(:options) { { :mode => name, :tag_sets => tag_sets } }
|
36
|
+
let(:selector) { described_class.new(options) }
|
37
|
+
|
38
|
+
before(:all) do
|
39
|
+
module Mongo
|
40
|
+
# We monkey-patch the server here, so the monitors do not run and no
|
41
|
+
# real TCP connection is attempted.
|
42
|
+
#
|
43
|
+
# @since 2.1.0
|
44
|
+
class Server
|
45
|
+
|
46
|
+
alias :original_initialize :initialize
|
47
|
+
def initialize(address, cluster, monitoring, event_listeners, options = {})
|
48
|
+
@address = address
|
49
|
+
@cluster = cluster
|
50
|
+
@monitoring = monitoring
|
51
|
+
@options = options.freeze
|
52
|
+
@monitor = Monitor.new(address, event_listeners, options)
|
53
|
+
end
|
54
|
+
|
55
|
+
alias :original_disconnect! :disconnect!
|
56
|
+
def disconnect!; true; end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
after(:all) do
|
62
|
+
|
63
|
+
# Return the server implementation to its original for the other
|
64
|
+
# tests in the suite.
|
65
|
+
module Mongo
|
66
|
+
class Server
|
67
|
+
alias :initialize :original_initialize
|
68
|
+
remove_method(:original_initialize)
|
69
|
+
|
70
|
+
alias :disconnect! :original_disconnect!
|
71
|
+
remove_method(:original_disconnect!)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
36
75
|
end
|
37
76
|
|
38
77
|
shared_examples 'a server selector mode' do
|
@@ -119,3 +158,20 @@ shared_examples 'a server selector accepting tag sets' do
|
|
119
158
|
end
|
120
159
|
end
|
121
160
|
end
|
161
|
+
|
162
|
+
shared_examples 'a server selector with sensitive data in its options' do
|
163
|
+
|
164
|
+
describe '#inspect' do
|
165
|
+
|
166
|
+
context 'when there is sensitive data in the options' do
|
167
|
+
|
168
|
+
let(:options) do
|
169
|
+
Mongo::Options::Redacted.new(:mode => name, :password => 'sensitive_data')
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'does not print out sensitive data' do
|
173
|
+
expect(selector.inspect).not_to match(options[:password])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|