mongo 2.7.0 → 2.7.1
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/README.md +39 -14
- data/Rakefile +1 -0
- data/lib/mongo/auth.rb +4 -1
- data/lib/mongo/client.rb +4 -3
- data/lib/mongo/cluster.rb +1 -1
- data/lib/mongo/collection/view/readable.rb +5 -2
- data/lib/mongo/database.rb +1 -0
- data/lib/mongo/error/invalid_server_preference.rb +1 -0
- data/lib/mongo/error/operation_failure.rb +10 -0
- data/lib/mongo/error/parser.rb +10 -0
- data/lib/mongo/event.rb +1 -2
- data/lib/mongo/operation/result.rb +4 -1
- data/lib/mongo/operation/shared/executable_transaction_label.rb +3 -1
- data/lib/mongo/operation/shared/sessions_supported.rb +1 -1
- data/lib/mongo/protocol/msg.rb +1 -1
- data/lib/mongo/protocol/query.rb +2 -2
- data/lib/mongo/retryable.rb +20 -6
- data/lib/mongo/server.rb +6 -0
- data/lib/mongo/server/connection.rb +4 -4
- data/lib/mongo/server/monitor/connection.rb +9 -5
- data/lib/mongo/server_selector/selectable.rb +86 -32
- data/lib/mongo/session.rb +98 -15
- data/lib/mongo/version.rb +1 -1
- data/spec/README.md +85 -0
- data/spec/integration/bulk_insert_spec.rb +1 -1
- data/spec/integration/change_stream_examples_spec.rb +3 -1
- data/spec/integration/change_stream_spec.rb +10 -14
- data/spec/integration/client_construction_spec.rb +1 -0
- data/spec/integration/command_monitoring_spec.rb +37 -1
- data/spec/integration/command_spec.rb +141 -0
- data/spec/integration/connection_spec.rb +4 -2
- data/spec/integration/cursor_reaping_spec.rb +1 -1
- data/spec/integration/docs_examples_spec.rb +1 -1
- data/spec/integration/retryable_writes_spec.rb +33 -42
- data/spec/integration/server_description_spec.rb +3 -3
- data/spec/integration/server_selector_spec.rb +79 -0
- data/spec/lite_spec_helper.rb +4 -2
- data/spec/mongo/address_spec.rb +8 -0
- data/spec/mongo/auth/cr_spec.rb +5 -2
- data/spec/mongo/auth/invalid_mechanism_spec.rb +11 -0
- data/spec/mongo/auth/scram/conversation_spec.rb +3 -2
- data/spec/mongo/auth/scram/negotiation_spec.rb +1 -2
- data/spec/mongo/auth/scram_spec.rb +11 -6
- data/spec/mongo/auth/user/view_spec.rb +13 -6
- data/spec/mongo/bulk_write_spec.rb +81 -104
- data/spec/mongo/client_construction_spec.rb +18 -7
- data/spec/mongo/client_spec.rb +11 -7
- data/spec/mongo/cluster_spec.rb +30 -1
- data/spec/mongo/collection/view/aggregation_spec.rb +18 -10
- data/spec/mongo/collection/view/change_stream_spec.rb +28 -8
- data/spec/mongo/collection/view/map_reduce_spec.rb +24 -10
- data/spec/mongo/collection/view/readable_spec.rb +37 -19
- data/spec/mongo/collection/view/writable_spec.rb +64 -32
- data/spec/mongo/collection/view_spec.rb +4 -2
- data/spec/mongo/collection_spec.rb +163 -73
- data/spec/mongo/cursor_spec.rb +5 -2
- data/spec/mongo/database_spec.rb +41 -19
- data/spec/mongo/error/no_server_available_spec.rb +1 -1
- data/spec/mongo/error/parser_spec.rb +29 -0
- data/spec/mongo/grid/stream/write_spec.rb +2 -1
- data/spec/mongo/index/view_spec.rb +42 -24
- data/spec/mongo/operation/delete/op_msg_spec.rb +11 -7
- data/spec/mongo/operation/insert/op_msg_spec.rb +10 -6
- data/spec/mongo/operation/update/op_msg_spec.rb +10 -6
- data/spec/mongo/protocol/compressed_spec.rb +1 -1
- data/spec/mongo/protocol/msg_spec.rb +1 -1
- data/spec/mongo/server/app_metadata_spec.rb +2 -1
- data/spec/mongo/server/connection_auth_spec.rb +1 -1
- data/spec/mongo/server/monitor/connection_spec.rb +42 -0
- data/spec/mongo/server_selector_spec.rb +17 -0
- data/spec/mongo/server_spec.rb +110 -0
- data/spec/mongo/session/session_pool_spec.rb +1 -1
- data/spec/mongo/session_spec.rb +1 -1
- data/spec/mongo/session_transaction_spec.rb +162 -1
- data/spec/mongo/socket/ssl_spec.rb +14 -7
- data/spec/mongo/uri/srv_protocol_spec.rb +41 -34
- data/spec/spec_helper.rb +3 -191
- data/spec/spec_tests/change_streams_spec.rb +3 -6
- data/spec/spec_tests/data/transactions/abort.yml +3 -1
- data/spec/spec_tests/data/transactions/commit.yml +4 -3
- data/spec/spec_tests/data/transactions/error-labels.yml +17 -13
- data/spec/spec_tests/data/transactions/read-concern.yml +611 -0
- data/spec/spec_tests/data/transactions/retryable-commit.yml +126 -21
- data/spec/spec_tests/data/transactions_api/callback-aborts.yml +42 -39
- data/spec/spec_tests/data/transactions_api/callback-commits.yml +52 -50
- data/spec/spec_tests/data/transactions_api/callback-retry.yml +33 -31
- data/spec/spec_tests/data/transactions_api/commit-retry.yml +42 -39
- data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +13 -12
- data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +15 -26
- data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +25 -33
- data/spec/spec_tests/data/transactions_api/commit.yml +44 -42
- data/spec/spec_tests/data/transactions_api/transaction-options.yml +25 -23
- data/spec/spec_tests/max_staleness_spec.rb +2 -0
- data/spec/spec_tests/retryable_writes_spec.rb +2 -6
- data/spec/spec_tests/sdam_spec.rb +2 -0
- data/spec/spec_tests/server_selection_spec.rb +3 -0
- data/spec/spec_tests/transactions_api_spec.rb +7 -1
- data/spec/spec_tests/transactions_spec.rb +6 -0
- data/spec/spec_tests/uri_options_spec.rb +4 -26
- data/spec/support/certificates/ca.pem +21 -16
- data/spec/support/certificates/client.pem +90 -90
- data/spec/support/certificates/client_cert.pem +21 -20
- data/spec/support/certificates/client_key.pem +27 -28
- data/spec/support/certificates/client_key_encrypted.pem +26 -26
- data/spec/support/certificates/crl.pem +10 -8
- data/spec/support/certificates/crl_client_revoked.pem +11 -10
- data/spec/support/certificates/server.pem +48 -33
- data/spec/support/change_streams.rb +12 -32
- data/spec/support/client_registry.rb +12 -1
- data/spec/support/cluster_config.rb +48 -2
- data/spec/support/common_shortcuts.rb +73 -7
- data/spec/support/connection_string.rb +0 -3
- data/spec/support/constraints.rb +87 -22
- data/spec/support/crud.rb +2 -1
- data/spec/support/shared/server_selector.rb +0 -28
- data/spec/support/shared/session.rb +25 -14
- data/spec/support/transactions.rb +4 -8
- data/spec/support/transactions/operation.rb +26 -4
- data/spec/support/transactions/verifier.rb +5 -2
- metadata +496 -488
- metadata.gz.sig +5 -2
- data/spec/support/certificates/password_protected.pem +0 -51
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe 'Server description' do
|
4
4
|
describe '#op_time' do
|
5
5
|
require_topology :replica_set
|
6
|
-
|
6
|
+
min_server_fcv '3.4'
|
7
7
|
|
8
8
|
let(:client) { ClientRegistry.instance.global_client('authorized') }
|
9
9
|
let(:desc) { client.cluster.servers.first.description }
|
@@ -17,7 +17,7 @@ describe 'Server description' do
|
|
17
17
|
|
18
18
|
describe '#last_write_date' do
|
19
19
|
require_topology :replica_set
|
20
|
-
|
20
|
+
min_server_fcv '3.4'
|
21
21
|
|
22
22
|
let(:client) { ClientRegistry.instance.global_client('authorized') }
|
23
23
|
let(:desc) { client.cluster.servers.first.description }
|
@@ -35,7 +35,7 @@ describe 'Server description' do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
let(:client) { ClientRegistry.instance.global_client('authorized') }
|
38
|
-
let(:desc) { client.cluster.
|
38
|
+
let(:desc) { client.cluster.next_primary.description }
|
39
39
|
|
40
40
|
it 'is set' do
|
41
41
|
client.database.command(ismaster: 1)
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Server selector' do
|
4
|
+
let(:selector) { Mongo::ServerSelector::Primary.new }
|
5
|
+
let(:client) { authorized_client }
|
6
|
+
let(:cluster) { client.cluster }
|
7
|
+
|
8
|
+
describe '#select_server' do
|
9
|
+
let(:result) { selector.select_server(cluster) }
|
10
|
+
|
11
|
+
it 'selects' do
|
12
|
+
expect(result).to be_a(Mongo::Server)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'no servers in the cluster' do
|
16
|
+
let(:client) { Mongo::Client.new([], server_selection_timeout: 2) }
|
17
|
+
|
18
|
+
it 'raises NoServerAvailable with a message explaining the situation' do
|
19
|
+
expect do
|
20
|
+
result
|
21
|
+
end.to raise_error(Mongo::Error::NoServerAvailable, "Cluster has no addresses, and therefore will never have a server")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'does not wait for server selection timeout' do
|
25
|
+
start_time = Time.now
|
26
|
+
expect do
|
27
|
+
result
|
28
|
+
end.to raise_error(Mongo::Error::NoServerAvailable)
|
29
|
+
time_passed = Time.now - start_time
|
30
|
+
expect(time_passed < 1).to be true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'client is closed' do
|
35
|
+
context 'there is a known primary' do
|
36
|
+
before do
|
37
|
+
client.cluster.next_primary
|
38
|
+
client.close
|
39
|
+
expect(client.cluster.connected?).to be false
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns the primary for BC reasons' do
|
43
|
+
expect(result).to be_a(Mongo::Server)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'there is no known primary' do
|
48
|
+
before do
|
49
|
+
primary_server = client.cluster.next_primary
|
50
|
+
client.close
|
51
|
+
expect(client.cluster.connected?).to be false
|
52
|
+
primary_server.unknown!
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'raises NoServerAvailable with a message explaining the situation' do
|
56
|
+
expect do
|
57
|
+
result
|
58
|
+
end.to raise_error(Mongo::Error::NoServerAvailable, /The cluster is disconnected \(client may have been closed\)/)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'monitoring thread is dead' do
|
64
|
+
before do
|
65
|
+
client.cluster.servers.first.monitor.instance_variable_get('@thread').kill
|
66
|
+
server = client.cluster.next_primary
|
67
|
+
if server
|
68
|
+
server.monitor.instance_variable_set('@description', Mongo::Server::Description.new({}))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'raises NoServerAvailable with a message explaining the situation' do
|
73
|
+
expect do
|
74
|
+
result
|
75
|
+
end.to raise_error(Mongo::Error::NoServerAvailable, /The following servers have dead monitor threads/)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/spec/lite_spec_helper.rb
CHANGED
@@ -24,7 +24,6 @@ if ENV['DRIVERS_TOOLS']
|
|
24
24
|
else
|
25
25
|
SSL_CERTS_DIR = "#{CURRENT_PATH}/support/certificates"
|
26
26
|
CLIENT_PEM = "#{SSL_CERTS_DIR}/client.pem"
|
27
|
-
CLIENT_PASSWORD_PEM = "#{SSL_CERTS_DIR}/password_protected.pem"
|
28
27
|
CA_PEM = "#{SSL_CERTS_DIR}/ca.pem"
|
29
28
|
CRL_PEM = "#{SSL_CERTS_DIR}/crl.pem"
|
30
29
|
CLIENT_KEY_PEM = "#{SSL_CERTS_DIR}/client_key.pem"
|
@@ -57,6 +56,8 @@ unless SpecConfig.instance.client_debug?
|
|
57
56
|
end
|
58
57
|
Encoding.default_external = Encoding::UTF_8
|
59
58
|
|
59
|
+
autoload :Timecop, 'timecop'
|
60
|
+
|
60
61
|
require 'ice_nine'
|
61
62
|
require 'support/matchers'
|
62
63
|
require 'support/lite_constraints'
|
@@ -85,7 +86,8 @@ else
|
|
85
86
|
end
|
86
87
|
|
87
88
|
RSpec.configure do |config|
|
88
|
-
config.extend(CommonShortcuts)
|
89
|
+
config.extend(CommonShortcuts::ClassMethods)
|
90
|
+
config.include(CommonShortcuts::InstanceMethods)
|
89
91
|
config.extend(LiteConstraints)
|
90
92
|
config.include(ClientRegistryMacros)
|
91
93
|
|
data/spec/mongo/address_spec.rb
CHANGED
@@ -320,4 +320,12 @@ describe Mongo::Address do
|
|
320
320
|
end
|
321
321
|
end
|
322
322
|
end
|
323
|
+
|
324
|
+
describe '#connect_timeout' do
|
325
|
+
let(:address) { Mongo::Address.new('127.0.0.1') }
|
326
|
+
|
327
|
+
it 'defaults to 10' do
|
328
|
+
expect(address.send(:connect_timeout)).to eq(10)
|
329
|
+
end
|
330
|
+
end
|
323
331
|
end
|
data/spec/mongo/auth/cr_spec.rb
CHANGED
@@ -64,7 +64,9 @@ describe Mongo::Auth::CR do
|
|
64
64
|
}.to raise_error(Mongo::Auth::Unauthorized)
|
65
65
|
end
|
66
66
|
|
67
|
-
context 'when compression is used'
|
67
|
+
context 'when compression is used' do
|
68
|
+
require_compression
|
69
|
+
min_server_fcv '3.6'
|
68
70
|
|
69
71
|
it 'does not compress the message' do
|
70
72
|
expect(Mongo::Protocol::Compressed).not_to receive(:new)
|
@@ -77,6 +79,7 @@ describe Mongo::Auth::CR do
|
|
77
79
|
end
|
78
80
|
|
79
81
|
context 'when the user is authorized for the database' do
|
82
|
+
max_server_fcv '2.6'
|
80
83
|
|
81
84
|
let(:cr) do
|
82
85
|
described_class.new(root_user)
|
@@ -86,7 +89,7 @@ describe Mongo::Auth::CR do
|
|
86
89
|
cr.login(connection).documents[0]
|
87
90
|
end
|
88
91
|
|
89
|
-
it 'logs the user into the connection'
|
92
|
+
it 'logs the user into the connection' do
|
90
93
|
expect(cr.login(connection).documents[0]['ok']).to eq(1)
|
91
94
|
end
|
92
95
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'lite_spec_helper'
|
2
|
+
|
3
|
+
describe Mongo::Auth::InvalidMechanism do
|
4
|
+
describe 'message' do
|
5
|
+
let(:exception) { described_class.new(:foo) }
|
6
|
+
|
7
|
+
it 'includes all built in mechanisms' do
|
8
|
+
expect(exception.message).to eq(':foo is invalid, please use one of the following mechanisms: :mongodb_cr, :mongodb_x509, :plain, :scram, :scram256')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -7,7 +7,8 @@ describe Mongo::Auth::SCRAM::Conversation, retry: 3 do
|
|
7
7
|
described_class.new(user, mechanism)
|
8
8
|
end
|
9
9
|
|
10
|
-
context 'when SCRAM-SHA-1 is used'
|
10
|
+
context 'when SCRAM-SHA-1 is used' do
|
11
|
+
min_server_fcv '3.0'
|
11
12
|
|
12
13
|
let(:user) do
|
13
14
|
Mongo::Auth::User.new(
|
@@ -208,7 +209,7 @@ describe Mongo::Auth::SCRAM::Conversation, retry: 3 do
|
|
208
209
|
end
|
209
210
|
|
210
211
|
context 'when SCRAM-SHA-256 is used' do
|
211
|
-
|
212
|
+
min_server_fcv '4.0'
|
212
213
|
|
213
214
|
let(:user) do
|
214
215
|
Mongo::Auth::User.new(
|
@@ -39,6 +39,7 @@ describe Mongo::Auth::SCRAM do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
context 'when SCRAM-SHA-1 is used' do
|
42
|
+
min_server_fcv '3.0'
|
42
43
|
|
43
44
|
describe '#login' do
|
44
45
|
|
@@ -57,13 +58,15 @@ describe Mongo::Auth::SCRAM do
|
|
57
58
|
described_class.new(user)
|
58
59
|
end
|
59
60
|
|
60
|
-
it 'raises an exception'
|
61
|
+
it 'raises an exception' do
|
61
62
|
expect {
|
62
63
|
cr.login(connection)
|
63
64
|
}.to raise_error(Mongo::Auth::Unauthorized)
|
64
65
|
end
|
65
66
|
|
66
|
-
context 'when compression is used'
|
67
|
+
context 'when compression is used' do
|
68
|
+
require_compression
|
69
|
+
min_server_fcv '3.6'
|
67
70
|
|
68
71
|
it 'does not compress the message' do
|
69
72
|
expect(Mongo::Protocol::Compressed).not_to receive(:new)
|
@@ -88,12 +91,12 @@ describe Mongo::Auth::SCRAM do
|
|
88
91
|
root_user.instance_variable_set(:@client_key, nil)
|
89
92
|
end
|
90
93
|
|
91
|
-
it 'logs the user into the connection and caches the client key'
|
94
|
+
it 'logs the user into the connection and caches the client key' do
|
92
95
|
expect(login['ok']).to eq(1)
|
93
96
|
expect(root_user.send(:client_key)).not_to be_nil
|
94
97
|
end
|
95
98
|
|
96
|
-
it 'raises an exception when an incorrect client key is set'
|
99
|
+
it 'raises an exception when an incorrect client key is set' do
|
97
100
|
root_user.instance_variable_set(:@client_key, "incorrect client key")
|
98
101
|
expect {
|
99
102
|
cr.login(connection)
|
@@ -104,7 +107,7 @@ describe Mongo::Auth::SCRAM do
|
|
104
107
|
end
|
105
108
|
|
106
109
|
context 'when SCRAM-SHA-256 is used' do
|
107
|
-
|
110
|
+
min_server_fcv '4.0'
|
108
111
|
|
109
112
|
describe '#login' do
|
110
113
|
|
@@ -129,7 +132,9 @@ describe Mongo::Auth::SCRAM do
|
|
129
132
|
}.to raise_error(Mongo::Auth::Unauthorized)
|
130
133
|
end
|
131
134
|
|
132
|
-
context 'when compression is used'
|
135
|
+
context 'when compression is used' do
|
136
|
+
require_compression
|
137
|
+
min_server_fcv '3.6'
|
133
138
|
|
134
139
|
it 'does not compress the message' do
|
135
140
|
expect(Mongo::Protocol::Compressed).not_to receive(:new)
|
@@ -30,7 +30,9 @@ describe Mongo::Auth::User::View do
|
|
30
30
|
expect(response).to be_successful
|
31
31
|
end
|
32
32
|
|
33
|
-
context 'when compression is used'
|
33
|
+
context 'when compression is used' do
|
34
|
+
require_compression
|
35
|
+
min_server_fcv '3.6'
|
34
36
|
|
35
37
|
it 'does not compress the message' do
|
36
38
|
# The dropUser command message will be compressed, so expect instantiation once.
|
@@ -97,7 +99,9 @@ describe Mongo::Auth::User::View do
|
|
97
99
|
expect(response).to be_successful
|
98
100
|
end
|
99
101
|
|
100
|
-
context 'when compression is used'
|
102
|
+
context 'when compression is used' do
|
103
|
+
require_compression
|
104
|
+
min_server_fcv '3.6'
|
101
105
|
|
102
106
|
it 'does not compress the message' do
|
103
107
|
# The dropUser command message will be compressed, so expect instantiation once.
|
@@ -145,7 +149,9 @@ describe Mongo::Auth::User::View do
|
|
145
149
|
expect(response).to be_successful
|
146
150
|
end
|
147
151
|
|
148
|
-
context 'when compression is used'
|
152
|
+
context 'when compression is used' do
|
153
|
+
require_compression
|
154
|
+
min_server_fcv '3.6'
|
149
155
|
|
150
156
|
it 'does not compress the message' do
|
151
157
|
# The dropUser command message will be compressed, so expect instantiation once.
|
@@ -286,15 +292,16 @@ describe Mongo::Auth::User::View do
|
|
286
292
|
end
|
287
293
|
|
288
294
|
context 'when a user is not authorized' do
|
295
|
+
require_auth
|
289
296
|
|
290
297
|
let(:view) do
|
291
298
|
described_class.new(unauthorized_client.database)
|
292
299
|
end
|
293
300
|
|
294
|
-
it 'raises an OperationFailure'
|
295
|
-
expect
|
301
|
+
it 'raises an OperationFailure' do
|
302
|
+
expect do
|
296
303
|
view.info('emily')
|
297
|
-
|
304
|
+
end.to raise_exception(Mongo::Error::OperationFailure)
|
298
305
|
end
|
299
306
|
end
|
300
307
|
end
|
@@ -26,6 +26,16 @@ describe Mongo::BulkWrite do
|
|
26
26
|
authorized_client
|
27
27
|
end
|
28
28
|
|
29
|
+
shared_examples_for 'bulk write with write concern yielding operation failure' do
|
30
|
+
require_topology :single
|
31
|
+
|
32
|
+
it 'raises an OperationFailure' do
|
33
|
+
expect {
|
34
|
+
bulk_write_invalid_write_concern.execute
|
35
|
+
}.to raise_error(Mongo::Error::OperationFailure)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
29
39
|
describe '#execute' do
|
30
40
|
shared_examples_for 'an executable bulk write' do
|
31
41
|
|
@@ -130,11 +140,7 @@ describe Mongo::BulkWrite do
|
|
130
140
|
|
131
141
|
context 'when there is a write concern error' do
|
132
142
|
|
133
|
-
|
134
|
-
expect {
|
135
|
-
bulk_write_invalid_write_concern.execute
|
136
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
137
|
-
end
|
143
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
138
144
|
|
139
145
|
context 'when a session is provided' do
|
140
146
|
|
@@ -189,11 +195,7 @@ describe Mongo::BulkWrite do
|
|
189
195
|
|
190
196
|
context 'when there is a write concern error' do
|
191
197
|
|
192
|
-
|
193
|
-
expect {
|
194
|
-
bulk_write_invalid_write_concern.execute
|
195
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
196
|
-
end
|
198
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
197
199
|
|
198
200
|
context 'when a session is provided' do
|
199
201
|
|
@@ -252,11 +254,7 @@ describe Mongo::BulkWrite do
|
|
252
254
|
|
253
255
|
context 'when there is a write concern error' do
|
254
256
|
|
255
|
-
|
256
|
-
expect {
|
257
|
-
bulk_write_invalid_write_concern.execute
|
258
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
259
|
-
end
|
257
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
260
258
|
|
261
259
|
context 'when a session is provided' do
|
262
260
|
|
@@ -285,7 +283,8 @@ describe Mongo::BulkWrite do
|
|
285
283
|
[{ delete_one: { filter: { name: 'BANG' }, collation: collation } }]
|
286
284
|
end
|
287
285
|
|
288
|
-
context 'when the server selected supports collations'
|
286
|
+
context 'when the server selected supports collations' do
|
287
|
+
min_server_fcv '3.4'
|
289
288
|
|
290
289
|
let!(:result) do
|
291
290
|
bulk_write.execute
|
@@ -300,7 +299,8 @@ describe Mongo::BulkWrite do
|
|
300
299
|
end
|
301
300
|
end
|
302
301
|
|
303
|
-
context 'when the server selected does not support collations'
|
302
|
+
context 'when the server selected does not support collations' do
|
303
|
+
max_server_version '3.2'
|
304
304
|
|
305
305
|
it 'raises an exception' do
|
306
306
|
expect {
|
@@ -365,7 +365,8 @@ describe Mongo::BulkWrite do
|
|
365
365
|
}]
|
366
366
|
end
|
367
367
|
|
368
|
-
context 'when the server selected supports arrayFilters'
|
368
|
+
context 'when the server selected supports arrayFilters' do
|
369
|
+
min_server_fcv '3.6'
|
369
370
|
|
370
371
|
let!(:result) do
|
371
372
|
bulk_write.execute
|
@@ -378,7 +379,8 @@ describe Mongo::BulkWrite do
|
|
378
379
|
end
|
379
380
|
end
|
380
381
|
|
381
|
-
context 'when the server selected does not support arrayFilters'
|
382
|
+
context 'when the server selected does not support arrayFilters' do
|
383
|
+
max_server_version '3.4'
|
382
384
|
|
383
385
|
it 'raises an exception' do
|
384
386
|
expect {
|
@@ -425,7 +427,8 @@ describe Mongo::BulkWrite do
|
|
425
427
|
}]
|
426
428
|
end
|
427
429
|
|
428
|
-
context 'when the server selected supports arrayFilters'
|
430
|
+
context 'when the server selected supports arrayFilters' do
|
431
|
+
min_server_fcv '3.6'
|
429
432
|
|
430
433
|
let!(:result) do
|
431
434
|
bulk_write.execute
|
@@ -441,7 +444,8 @@ describe Mongo::BulkWrite do
|
|
441
444
|
end
|
442
445
|
end
|
443
446
|
|
444
|
-
context 'when the server selected does not support arrayFilters'
|
447
|
+
context 'when the server selected does not support arrayFilters' do
|
448
|
+
max_server_version '3.4'
|
445
449
|
|
446
450
|
it 'raises an exception' do
|
447
451
|
expect {
|
@@ -517,12 +521,7 @@ describe Mongo::BulkWrite do
|
|
517
521
|
|
518
522
|
context 'when there is a write concern error' do
|
519
523
|
|
520
|
-
|
521
|
-
it 'raises an OperationFailure', if: standalone? do
|
522
|
-
expect {
|
523
|
-
bulk_write_invalid_write_concern.execute
|
524
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
525
|
-
end
|
524
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
526
525
|
|
527
526
|
context 'when a session is provided' do
|
528
527
|
|
@@ -554,7 +553,8 @@ describe Mongo::BulkWrite do
|
|
554
553
|
{ delete_one: { filter: { name: 'DOINK' }, collation: collation }}]
|
555
554
|
end
|
556
555
|
|
557
|
-
context 'when the server selected supports collations'
|
556
|
+
context 'when the server selected supports collations' do
|
557
|
+
min_server_fcv '3.4'
|
558
558
|
|
559
559
|
let!(:result) do
|
560
560
|
bulk_write.execute
|
@@ -569,7 +569,8 @@ describe Mongo::BulkWrite do
|
|
569
569
|
end
|
570
570
|
end
|
571
571
|
|
572
|
-
context 'when the server selected does not support collations'
|
572
|
+
context 'when the server selected does not support collations' do
|
573
|
+
max_server_version '3.2'
|
573
574
|
|
574
575
|
it 'raises an exception' do
|
575
576
|
expect {
|
@@ -657,11 +658,7 @@ describe Mongo::BulkWrite do
|
|
657
658
|
|
658
659
|
context 'when there is a write concern error' do
|
659
660
|
|
660
|
-
|
661
|
-
expect {
|
662
|
-
bulk_write_invalid_write_concern.execute
|
663
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
664
|
-
end
|
661
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
665
662
|
|
666
663
|
context 'when a session is provided' do
|
667
664
|
|
@@ -692,7 +689,8 @@ describe Mongo::BulkWrite do
|
|
692
689
|
[{ delete_many: { filter: { name: 'BANG' }, collation: collation }}]
|
693
690
|
end
|
694
691
|
|
695
|
-
context 'when the server selected supports collations'
|
692
|
+
context 'when the server selected supports collations' do
|
693
|
+
min_server_fcv '3.4'
|
696
694
|
|
697
695
|
let!(:result) do
|
698
696
|
bulk_write.execute
|
@@ -707,7 +705,8 @@ describe Mongo::BulkWrite do
|
|
707
705
|
end
|
708
706
|
end
|
709
707
|
|
710
|
-
context 'when the server selected does not support collations'
|
708
|
+
context 'when the server selected does not support collations' do
|
709
|
+
max_server_version '3.2'
|
711
710
|
|
712
711
|
it 'raises an exception' do
|
713
712
|
expect {
|
@@ -799,11 +798,7 @@ describe Mongo::BulkWrite do
|
|
799
798
|
|
800
799
|
context 'when there is a write concern error' do
|
801
800
|
|
802
|
-
|
803
|
-
expect {
|
804
|
-
bulk_write_invalid_write_concern.execute
|
805
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
806
|
-
end
|
801
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
807
802
|
|
808
803
|
context 'when a session is provided' do
|
809
804
|
|
@@ -836,7 +831,8 @@ describe Mongo::BulkWrite do
|
|
836
831
|
{ delete_many: { filter: { name: 'DOINK' }, collation: collation }}]
|
837
832
|
end
|
838
833
|
|
839
|
-
context 'when the server selected supports collations'
|
834
|
+
context 'when the server selected supports collations' do
|
835
|
+
min_server_fcv '3.4'
|
840
836
|
|
841
837
|
let!(:result) do
|
842
838
|
bulk_write.execute
|
@@ -851,7 +847,8 @@ describe Mongo::BulkWrite do
|
|
851
847
|
end
|
852
848
|
end
|
853
849
|
|
854
|
-
context 'when the server selected does not support collations'
|
850
|
+
context 'when the server selected does not support collations' do
|
851
|
+
max_server_version '3.2'
|
855
852
|
|
856
853
|
it 'raises an exception' do
|
857
854
|
expect {
|
@@ -940,11 +937,7 @@ describe Mongo::BulkWrite do
|
|
940
937
|
|
941
938
|
context 'when there is a write concern error' do
|
942
939
|
|
943
|
-
|
944
|
-
expect {
|
945
|
-
bulk_write_invalid_write_concern.execute
|
946
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
947
|
-
end
|
940
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
948
941
|
|
949
942
|
context 'when a session is provided' do
|
950
943
|
|
@@ -977,33 +970,35 @@ describe Mongo::BulkWrite do
|
|
977
970
|
end
|
978
971
|
|
979
972
|
context 'when the server selected supports collations' do
|
973
|
+
min_server_fcv '3.4'
|
980
974
|
|
981
975
|
let!(:result) do
|
982
976
|
bulk_write.execute
|
983
977
|
end
|
984
978
|
|
985
|
-
it 'applies the collation'
|
979
|
+
it 'applies the collation' do
|
986
980
|
expect(authorized_collection.find(other: 'pong').count).to eq(1)
|
987
981
|
end
|
988
982
|
|
989
|
-
it 'reports the upserted id'
|
983
|
+
it 'reports the upserted id' do
|
990
984
|
expect(result.upserted_ids).to eq([])
|
991
985
|
end
|
992
986
|
|
993
|
-
it 'reports the upserted count'
|
987
|
+
it 'reports the upserted count' do
|
994
988
|
expect(result.upserted_count).to eq(0)
|
995
989
|
end
|
996
990
|
|
997
|
-
it 'reports the modified count'
|
991
|
+
it 'reports the modified count' do
|
998
992
|
expect(result.modified_count).to eq(1)
|
999
993
|
end
|
1000
994
|
|
1001
|
-
it 'reports the matched count'
|
995
|
+
it 'reports the matched count' do
|
1002
996
|
expect(result.matched_count).to eq(1)
|
1003
997
|
end
|
1004
998
|
end
|
1005
999
|
|
1006
|
-
context 'when the server selected does not support collations'
|
1000
|
+
context 'when the server selected does not support collations' do
|
1001
|
+
max_server_version '3.2'
|
1007
1002
|
|
1008
1003
|
it 'raises an exception' do
|
1009
1004
|
expect {
|
@@ -1169,11 +1164,7 @@ describe Mongo::BulkWrite do
|
|
1169
1164
|
|
1170
1165
|
context 'when there is a write concern error' do
|
1171
1166
|
|
1172
|
-
|
1173
|
-
expect {
|
1174
|
-
bulk_write_invalid_write_concern.execute
|
1175
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
1176
|
-
end
|
1167
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
1177
1168
|
|
1178
1169
|
context 'when a session is provided' do
|
1179
1170
|
|
@@ -1227,11 +1218,7 @@ describe Mongo::BulkWrite do
|
|
1227
1218
|
|
1228
1219
|
context 'when there is a write concern error' do
|
1229
1220
|
|
1230
|
-
|
1231
|
-
expect {
|
1232
|
-
bulk_write_invalid_write_concern.execute
|
1233
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
1234
|
-
end
|
1221
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
1235
1222
|
end
|
1236
1223
|
|
1237
1224
|
context 'when write_concern is specified as an option' do
|
@@ -1280,33 +1267,35 @@ describe Mongo::BulkWrite do
|
|
1280
1267
|
end
|
1281
1268
|
|
1282
1269
|
context 'when the server selected supports collations' do
|
1270
|
+
min_server_fcv '3.4'
|
1283
1271
|
|
1284
1272
|
let!(:result) do
|
1285
1273
|
bulk_write.execute
|
1286
1274
|
end
|
1287
1275
|
|
1288
|
-
it 'applies the collation'
|
1276
|
+
it 'applies the collation' do
|
1289
1277
|
expect(authorized_collection.find(name: 'pong').count).to eq(1)
|
1290
1278
|
end
|
1291
1279
|
|
1292
|
-
it 'reports the upserted id'
|
1280
|
+
it 'reports the upserted id' do
|
1293
1281
|
expect(result.upserted_ids).to eq([])
|
1294
1282
|
end
|
1295
1283
|
|
1296
|
-
it 'reports the upserted count'
|
1284
|
+
it 'reports the upserted count' do
|
1297
1285
|
expect(result.upserted_count).to eq(0)
|
1298
1286
|
end
|
1299
1287
|
|
1300
|
-
it 'reports the modified count'
|
1288
|
+
it 'reports the modified count' do
|
1301
1289
|
expect(result.modified_count).to eq(1)
|
1302
1290
|
end
|
1303
1291
|
|
1304
|
-
it 'reports the matched count'
|
1292
|
+
it 'reports the matched count' do
|
1305
1293
|
expect(result.matched_count).to eq(1)
|
1306
1294
|
end
|
1307
1295
|
end
|
1308
1296
|
|
1309
|
-
context 'when the server selected does not support collations'
|
1297
|
+
context 'when the server selected does not support collations' do
|
1298
|
+
max_server_version '3.2'
|
1310
1299
|
|
1311
1300
|
it 'raises an exception' do
|
1312
1301
|
expect {
|
@@ -1386,33 +1375,35 @@ describe Mongo::BulkWrite do
|
|
1386
1375
|
end
|
1387
1376
|
|
1388
1377
|
context 'when the server selected supports collations' do
|
1378
|
+
min_server_fcv '3.4'
|
1389
1379
|
|
1390
1380
|
let!(:result) do
|
1391
1381
|
bulk_write.execute
|
1392
1382
|
end
|
1393
1383
|
|
1394
|
-
it 'applies the collation'
|
1384
|
+
it 'applies the collation' do
|
1395
1385
|
expect(authorized_collection.find(name: 'pong').count).to eq(2)
|
1396
1386
|
end
|
1397
1387
|
|
1398
|
-
it 'reports the upserted id'
|
1388
|
+
it 'reports the upserted id' do
|
1399
1389
|
expect(result.upserted_ids).to eq([])
|
1400
1390
|
end
|
1401
1391
|
|
1402
|
-
it 'reports the upserted count'
|
1392
|
+
it 'reports the upserted count' do
|
1403
1393
|
expect(result.upserted_count).to eq(0)
|
1404
1394
|
end
|
1405
1395
|
|
1406
|
-
it 'reports the modified count'
|
1396
|
+
it 'reports the modified count' do
|
1407
1397
|
expect(result.modified_count).to eq(2)
|
1408
1398
|
end
|
1409
1399
|
|
1410
|
-
it 'reports the matched count'
|
1400
|
+
it 'reports the matched count' do
|
1411
1401
|
expect(result.matched_count).to eq(2)
|
1412
1402
|
end
|
1413
1403
|
end
|
1414
1404
|
|
1415
|
-
context 'when the server selected does not support collations'
|
1405
|
+
context 'when the server selected does not support collations' do
|
1406
|
+
max_server_version '3.2'
|
1416
1407
|
|
1417
1408
|
it 'raises an exception' do
|
1418
1409
|
expect {
|
@@ -1552,11 +1543,7 @@ describe Mongo::BulkWrite do
|
|
1552
1543
|
|
1553
1544
|
context 'when there is a write concern error' do
|
1554
1545
|
|
1555
|
-
|
1556
|
-
expect {
|
1557
|
-
bulk_write_invalid_write_concern.execute
|
1558
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
1559
|
-
end
|
1546
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
1560
1547
|
end
|
1561
1548
|
end
|
1562
1549
|
|
@@ -1633,11 +1620,7 @@ describe Mongo::BulkWrite do
|
|
1633
1620
|
|
1634
1621
|
context 'when there is a write concern error' do
|
1635
1622
|
|
1636
|
-
|
1637
|
-
expect {
|
1638
|
-
bulk_write_invalid_write_concern.execute
|
1639
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
1640
|
-
end
|
1623
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
1641
1624
|
end
|
1642
1625
|
end
|
1643
1626
|
end
|
@@ -1658,33 +1641,35 @@ describe Mongo::BulkWrite do
|
|
1658
1641
|
end
|
1659
1642
|
|
1660
1643
|
context 'when the server selected supports collations' do
|
1644
|
+
min_server_fcv '3.4'
|
1661
1645
|
|
1662
1646
|
let!(:result) do
|
1663
1647
|
bulk_write.execute
|
1664
1648
|
end
|
1665
1649
|
|
1666
|
-
it 'applies the collation'
|
1650
|
+
it 'applies the collation' do
|
1667
1651
|
expect(authorized_collection.find(name: 'pong').count).to eq(2)
|
1668
1652
|
end
|
1669
1653
|
|
1670
|
-
it 'reports the upserted id'
|
1654
|
+
it 'reports the upserted id' do
|
1671
1655
|
expect(result.upserted_ids).to eq([])
|
1672
1656
|
end
|
1673
1657
|
|
1674
|
-
it 'reports the upserted count'
|
1658
|
+
it 'reports the upserted count' do
|
1675
1659
|
expect(result.upserted_count).to eq(0)
|
1676
1660
|
end
|
1677
1661
|
|
1678
|
-
it 'reports the modified count'
|
1662
|
+
it 'reports the modified count' do
|
1679
1663
|
expect(result.modified_count).to eq(2)
|
1680
1664
|
end
|
1681
1665
|
|
1682
|
-
it 'reports the matched count'
|
1666
|
+
it 'reports the matched count' do
|
1683
1667
|
expect(result.matched_count).to eq(2)
|
1684
1668
|
end
|
1685
1669
|
end
|
1686
1670
|
|
1687
|
-
context 'when the server selected does not support collations'
|
1671
|
+
context 'when the server selected does not support collations' do
|
1672
|
+
max_server_version '3.2'
|
1688
1673
|
|
1689
1674
|
it 'raises an exception' do
|
1690
1675
|
expect {
|
@@ -1781,11 +1766,7 @@ describe Mongo::BulkWrite do
|
|
1781
1766
|
|
1782
1767
|
context 'when there is a write concern error' do
|
1783
1768
|
|
1784
|
-
|
1785
|
-
expect {
|
1786
|
-
bulk_write_invalid_write_concern.execute
|
1787
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
1788
|
-
end
|
1769
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
1789
1770
|
end
|
1790
1771
|
end
|
1791
1772
|
|
@@ -1822,11 +1803,7 @@ describe Mongo::BulkWrite do
|
|
1822
1803
|
|
1823
1804
|
context 'when there is a write concern error' do
|
1824
1805
|
|
1825
|
-
|
1826
|
-
expect {
|
1827
|
-
bulk_write_invalid_write_concern.execute
|
1828
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
1829
|
-
end
|
1806
|
+
it_behaves_like 'bulk write with write concern yielding operation failure'
|
1830
1807
|
end
|
1831
1808
|
end
|
1832
1809
|
end
|
@@ -1909,7 +1886,7 @@ describe Mongo::BulkWrite do
|
|
1909
1886
|
end
|
1910
1887
|
|
1911
1888
|
context 'when retryable writes are supported' do
|
1912
|
-
|
1889
|
+
min_server_fcv '3.6'
|
1913
1890
|
require_topology :replica_set, :sharded
|
1914
1891
|
|
1915
1892
|
let(:subscriber) { EventSubscriber.new }
|
@@ -2142,7 +2119,7 @@ describe Mongo::BulkWrite do
|
|
2142
2119
|
end
|
2143
2120
|
|
2144
2121
|
describe 'when the collection has a validator' do
|
2145
|
-
|
2122
|
+
min_server_fcv '3.2'
|
2146
2123
|
|
2147
2124
|
let(:collection_with_validator) do
|
2148
2125
|
authorized_client[:validating,
|