mongo 2.7.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +39 -14
  5. data/Rakefile +1 -0
  6. data/lib/mongo/auth.rb +4 -1
  7. data/lib/mongo/client.rb +4 -3
  8. data/lib/mongo/cluster.rb +1 -1
  9. data/lib/mongo/collection/view/readable.rb +5 -2
  10. data/lib/mongo/database.rb +1 -0
  11. data/lib/mongo/error/invalid_server_preference.rb +1 -0
  12. data/lib/mongo/error/operation_failure.rb +10 -0
  13. data/lib/mongo/error/parser.rb +10 -0
  14. data/lib/mongo/event.rb +1 -2
  15. data/lib/mongo/operation/result.rb +4 -1
  16. data/lib/mongo/operation/shared/executable_transaction_label.rb +3 -1
  17. data/lib/mongo/operation/shared/sessions_supported.rb +1 -1
  18. data/lib/mongo/protocol/msg.rb +1 -1
  19. data/lib/mongo/protocol/query.rb +2 -2
  20. data/lib/mongo/retryable.rb +20 -6
  21. data/lib/mongo/server.rb +6 -0
  22. data/lib/mongo/server/connection.rb +4 -4
  23. data/lib/mongo/server/monitor/connection.rb +9 -5
  24. data/lib/mongo/server_selector/selectable.rb +86 -32
  25. data/lib/mongo/session.rb +98 -15
  26. data/lib/mongo/version.rb +1 -1
  27. data/spec/README.md +85 -0
  28. data/spec/integration/bulk_insert_spec.rb +1 -1
  29. data/spec/integration/change_stream_examples_spec.rb +3 -1
  30. data/spec/integration/change_stream_spec.rb +10 -14
  31. data/spec/integration/client_construction_spec.rb +1 -0
  32. data/spec/integration/command_monitoring_spec.rb +37 -1
  33. data/spec/integration/command_spec.rb +141 -0
  34. data/spec/integration/connection_spec.rb +4 -2
  35. data/spec/integration/cursor_reaping_spec.rb +1 -1
  36. data/spec/integration/docs_examples_spec.rb +1 -1
  37. data/spec/integration/retryable_writes_spec.rb +33 -42
  38. data/spec/integration/server_description_spec.rb +3 -3
  39. data/spec/integration/server_selector_spec.rb +79 -0
  40. data/spec/lite_spec_helper.rb +4 -2
  41. data/spec/mongo/address_spec.rb +8 -0
  42. data/spec/mongo/auth/cr_spec.rb +5 -2
  43. data/spec/mongo/auth/invalid_mechanism_spec.rb +11 -0
  44. data/spec/mongo/auth/scram/conversation_spec.rb +3 -2
  45. data/spec/mongo/auth/scram/negotiation_spec.rb +1 -2
  46. data/spec/mongo/auth/scram_spec.rb +11 -6
  47. data/spec/mongo/auth/user/view_spec.rb +13 -6
  48. data/spec/mongo/bulk_write_spec.rb +81 -104
  49. data/spec/mongo/client_construction_spec.rb +18 -7
  50. data/spec/mongo/client_spec.rb +11 -7
  51. data/spec/mongo/cluster_spec.rb +30 -1
  52. data/spec/mongo/collection/view/aggregation_spec.rb +18 -10
  53. data/spec/mongo/collection/view/change_stream_spec.rb +28 -8
  54. data/spec/mongo/collection/view/map_reduce_spec.rb +24 -10
  55. data/spec/mongo/collection/view/readable_spec.rb +37 -19
  56. data/spec/mongo/collection/view/writable_spec.rb +64 -32
  57. data/spec/mongo/collection/view_spec.rb +4 -2
  58. data/spec/mongo/collection_spec.rb +163 -73
  59. data/spec/mongo/cursor_spec.rb +5 -2
  60. data/spec/mongo/database_spec.rb +41 -19
  61. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  62. data/spec/mongo/error/parser_spec.rb +29 -0
  63. data/spec/mongo/grid/stream/write_spec.rb +2 -1
  64. data/spec/mongo/index/view_spec.rb +42 -24
  65. data/spec/mongo/operation/delete/op_msg_spec.rb +11 -7
  66. data/spec/mongo/operation/insert/op_msg_spec.rb +10 -6
  67. data/spec/mongo/operation/update/op_msg_spec.rb +10 -6
  68. data/spec/mongo/protocol/compressed_spec.rb +1 -1
  69. data/spec/mongo/protocol/msg_spec.rb +1 -1
  70. data/spec/mongo/server/app_metadata_spec.rb +2 -1
  71. data/spec/mongo/server/connection_auth_spec.rb +1 -1
  72. data/spec/mongo/server/monitor/connection_spec.rb +42 -0
  73. data/spec/mongo/server_selector_spec.rb +17 -0
  74. data/spec/mongo/server_spec.rb +110 -0
  75. data/spec/mongo/session/session_pool_spec.rb +1 -1
  76. data/spec/mongo/session_spec.rb +1 -1
  77. data/spec/mongo/session_transaction_spec.rb +162 -1
  78. data/spec/mongo/socket/ssl_spec.rb +14 -7
  79. data/spec/mongo/uri/srv_protocol_spec.rb +41 -34
  80. data/spec/spec_helper.rb +3 -191
  81. data/spec/spec_tests/change_streams_spec.rb +3 -6
  82. data/spec/spec_tests/data/transactions/abort.yml +3 -1
  83. data/spec/spec_tests/data/transactions/commit.yml +4 -3
  84. data/spec/spec_tests/data/transactions/error-labels.yml +17 -13
  85. data/spec/spec_tests/data/transactions/read-concern.yml +611 -0
  86. data/spec/spec_tests/data/transactions/retryable-commit.yml +126 -21
  87. data/spec/spec_tests/data/transactions_api/callback-aborts.yml +42 -39
  88. data/spec/spec_tests/data/transactions_api/callback-commits.yml +52 -50
  89. data/spec/spec_tests/data/transactions_api/callback-retry.yml +33 -31
  90. data/spec/spec_tests/data/transactions_api/commit-retry.yml +42 -39
  91. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +13 -12
  92. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +15 -26
  93. data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +25 -33
  94. data/spec/spec_tests/data/transactions_api/commit.yml +44 -42
  95. data/spec/spec_tests/data/transactions_api/transaction-options.yml +25 -23
  96. data/spec/spec_tests/max_staleness_spec.rb +2 -0
  97. data/spec/spec_tests/retryable_writes_spec.rb +2 -6
  98. data/spec/spec_tests/sdam_spec.rb +2 -0
  99. data/spec/spec_tests/server_selection_spec.rb +3 -0
  100. data/spec/spec_tests/transactions_api_spec.rb +7 -1
  101. data/spec/spec_tests/transactions_spec.rb +6 -0
  102. data/spec/spec_tests/uri_options_spec.rb +4 -26
  103. data/spec/support/certificates/ca.pem +21 -16
  104. data/spec/support/certificates/client.pem +90 -90
  105. data/spec/support/certificates/client_cert.pem +21 -20
  106. data/spec/support/certificates/client_key.pem +27 -28
  107. data/spec/support/certificates/client_key_encrypted.pem +26 -26
  108. data/spec/support/certificates/crl.pem +10 -8
  109. data/spec/support/certificates/crl_client_revoked.pem +11 -10
  110. data/spec/support/certificates/server.pem +48 -33
  111. data/spec/support/change_streams.rb +12 -32
  112. data/spec/support/client_registry.rb +12 -1
  113. data/spec/support/cluster_config.rb +48 -2
  114. data/spec/support/common_shortcuts.rb +73 -7
  115. data/spec/support/connection_string.rb +0 -3
  116. data/spec/support/constraints.rb +87 -22
  117. data/spec/support/crud.rb +2 -1
  118. data/spec/support/shared/server_selector.rb +0 -28
  119. data/spec/support/shared/session.rb +25 -14
  120. data/spec/support/transactions.rb +4 -8
  121. data/spec/support/transactions/operation.rb +26 -4
  122. data/spec/support/transactions/verifier.rb +5 -2
  123. metadata +496 -488
  124. metadata.gz.sig +5 -2
  125. 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
- min_server_version '3.4'
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
- min_server_version '3.4'
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.servers.first.description }
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
@@ -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
 
@@ -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
@@ -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', if: testing_compression? do
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', unless: scram_sha_1_enabled? do
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', if: scram_sha_1_enabled? do
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
- require_scram_sha_256_support
212
+ min_server_fcv '4.0'
212
213
 
213
214
  let(:user) do
214
215
  Mongo::Auth::User.new(
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
- require 'cgi'
3
2
 
4
3
  describe 'SCRAM-SHA auth mechanism negotiation' do
5
- require_scram_sha_256_support
4
+ min_server_fcv '4.0'
6
5
 
7
6
  before(:all) do
8
7
  ClientRegistry.instance.close_all_clients
@@ -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', if: scram_sha_1_enabled? do
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', if: testing_compression? do
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', if: scram_sha_1_enabled? do
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', if: scram_sha_1_enabled? do
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
- require_scram_sha_256_support
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', if: testing_compression? do
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', if: testing_compression? do
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', if: testing_compression? do
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', if: testing_compression? do
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', if: auth_enabled? do
295
- expect{
301
+ it 'raises an OperationFailure' do
302
+ expect do
296
303
  view.info('emily')
297
- }.to raise_exception(Mongo::Error::OperationFailure)
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
- it 'raises an OperationFailure', if: standalone? do
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
- it 'raises an OperationFailure', if: standalone? do
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
- it 'raises an OperationFailure', if: standalone? do
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', if: collation_enabled? do
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', unless: collation_enabled? do
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', if: array_filters_enabled? do
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', unless: array_filters_enabled? do
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', if: array_filters_enabled? do
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', unless: array_filters_enabled? do
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', if: collation_enabled? do
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', unless: collation_enabled? do
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
- it 'raises an OperationFailure', if: standalone? do
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', if: collation_enabled? do
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', unless: collation_enabled? do
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
- it 'raises an OperationFailure', if: standalone? do
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', if: collation_enabled? do
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', unless: collation_enabled? do
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
- it 'raises an OperationFailure', if: standalone? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', unless: collation_enabled? do
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
- it 'raises an OperationFailure', if: standalone? do
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
- it 'raises an OperationFailure', if: standalone? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', unless: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', unless: collation_enabled? do
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
- it 'raises an OperationFailure', if: standalone? do
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
- it 'raises an OperationFailure', if: standalone? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', if: collation_enabled? do
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', unless: collation_enabled? do
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
- it 'raises an OperationFailure', if: standalone? do
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
- it 'raises an OperationFailure', if: standalone? do
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
- min_server_version '3.6'
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
- min_server_version '3.2'
2122
+ min_server_fcv '3.2'
2146
2123
 
2147
2124
  let(:collection_with_validator) do
2148
2125
  authorized_client[:validating,