mongo 2.9.2 → 2.10.0.rc0
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/lib/mongo.rb +1 -0
- data/lib/mongo/auth/user/view.rb +4 -4
- data/lib/mongo/bulk_write.rb +14 -8
- data/lib/mongo/bulk_write/result.rb +1 -1
- data/lib/mongo/bulk_write/result_combiner.rb +2 -2
- data/lib/mongo/bulk_write/transformable.rb +17 -9
- data/lib/mongo/client.rb +107 -16
- data/lib/mongo/cluster.rb +47 -25
- data/lib/mongo/cluster/topology/replica_set_no_primary.rb +1 -1
- data/lib/mongo/cluster_time.rb +139 -0
- data/lib/mongo/collection.rb +84 -25
- data/lib/mongo/collection/view.rb +7 -3
- data/lib/mongo/collection/view/aggregation.rb +4 -4
- data/lib/mongo/collection/view/builder/aggregation.rb +31 -6
- data/lib/mongo/collection/view/builder/find_command.rb +4 -1
- data/lib/mongo/collection/view/builder/map_reduce.rb +4 -1
- data/lib/mongo/collection/view/change_stream.rb +54 -66
- data/lib/mongo/collection/view/iterable.rb +2 -2
- data/lib/mongo/collection/view/map_reduce.rb +6 -4
- data/lib/mongo/collection/view/readable.rb +36 -16
- data/lib/mongo/collection/view/writable.rb +68 -22
- data/lib/mongo/cursor.rb +87 -20
- data/lib/mongo/database.rb +47 -43
- data/lib/mongo/database/view.rb +54 -11
- data/lib/mongo/error.rb +13 -4
- data/lib/mongo/error/invalid_write_concern.rb +2 -2
- data/lib/mongo/error/operation_failure.rb +65 -11
- data/lib/mongo/error/parser.rb +41 -8
- data/lib/mongo/grid/fs_bucket.rb +26 -6
- data/lib/mongo/grid/stream/read.rb +9 -2
- data/lib/mongo/grid/stream/write.rb +21 -5
- data/lib/mongo/index/view.rb +3 -3
- data/lib/mongo/lint.rb +10 -3
- data/lib/mongo/operation.rb +2 -0
- data/lib/mongo/operation/aggregate/result.rb +19 -6
- data/lib/mongo/operation/collections_info.rb +1 -1
- data/lib/mongo/operation/get_more/result.rb +9 -0
- data/lib/mongo/operation/list_collections/command.rb +1 -3
- data/lib/mongo/operation/list_collections/op_msg.rb +1 -2
- data/lib/mongo/operation/parallel_scan/command.rb +4 -1
- data/lib/mongo/operation/parallel_scan/op_msg.rb +4 -1
- data/lib/mongo/operation/result.rb +27 -4
- data/lib/mongo/operation/shared/executable.rb +19 -5
- data/lib/mongo/operation/shared/executable_no_validate.rb +1 -2
- data/lib/mongo/operation/shared/executable_transaction_label.rb +0 -9
- data/lib/mongo/operation/shared/polymorphic_result.rb +9 -1
- data/lib/mongo/operation/shared/result/aggregatable.rb +2 -2
- data/lib/mongo/operation/shared/sessions_supported.rb +42 -32
- data/lib/mongo/operation/shared/specifiable.rb +40 -0
- data/lib/mongo/operation/shared/unpinnable.rb +39 -0
- data/lib/mongo/operation/shared/write.rb +1 -1
- data/lib/mongo/protocol/update.rb +6 -2
- data/lib/mongo/retryable.rb +79 -39
- data/lib/mongo/server/connection.rb +10 -3
- data/lib/mongo/server/description.rb +25 -1
- data/lib/mongo/server/monitor/connection.rb +1 -1
- data/lib/mongo/server_selector.rb +10 -0
- data/lib/mongo/server_selector/selectable.rb +172 -32
- data/lib/mongo/session.rb +654 -581
- data/lib/mongo/session/session_pool.rb +1 -1
- data/lib/mongo/socket.rb +7 -28
- data/lib/mongo/socket/ssl.rb +26 -1
- data/lib/mongo/socket/tcp.rb +3 -0
- data/lib/mongo/socket/unix.rb +3 -0
- data/lib/mongo/uri.rb +112 -265
- data/lib/mongo/uri/srv_protocol.rb +4 -1
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern.rb +10 -29
- data/lib/mongo/write_concern/acknowledged.rb +12 -0
- data/lib/mongo/write_concern/base.rb +17 -13
- data/lib/mongo/write_concern/unacknowledged.rb +12 -0
- data/spec/atlas/atlas_connectivity_spec.rb +7 -37
- data/spec/atlas/operations_spec.rb +25 -0
- data/spec/integration/change_stream_examples_spec.rb +45 -31
- data/spec/integration/change_stream_spec.rb +305 -5
- data/spec/integration/client_spec.rb +44 -0
- data/spec/integration/command_monitoring_spec.rb +1 -0
- data/spec/integration/command_spec.rb +7 -1
- data/spec/integration/mmapv1_spec.rb +28 -0
- data/spec/integration/mongos_pinning_spec.rb +34 -0
- data/spec/integration/operation_failure_code_spec.rb +2 -2
- data/spec/integration/{read_concern.rb → read_concern_spec.rb} +7 -1
- data/spec/integration/read_preference_spec.rb +485 -0
- data/spec/integration/retryable_writes_spec.rb +8 -19
- data/spec/integration/sdam_error_handling_spec.rb +1 -1
- data/spec/integration/sdam_events_spec.rb +2 -2
- data/spec/integration/server_description_spec.rb +14 -17
- data/spec/integration/server_selector_spec.rb +7 -3
- data/spec/integration/server_spec.rb +48 -0
- data/spec/integration/ssl_uri_options_spec.rb +1 -1
- data/spec/integration/step_down_spec.rb +10 -4
- data/spec/integration/transactions_examples_spec.rb +11 -10
- data/spec/lite_spec_helper.rb +19 -16
- data/spec/mongo/auth/scram/negotiation_spec.rb +11 -8
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +6 -6
- data/spec/mongo/bulk_write/unordered_combiner_spec.rb +4 -4
- data/spec/mongo/bulk_write_spec.rb +12 -2
- data/spec/mongo/client_construction_spec.rb +160 -8
- data/spec/mongo/client_spec.rb +5 -4
- data/spec/mongo/cluster_spec.rb +6 -6
- data/spec/mongo/cluster_time_spec.rb +148 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +34 -15
- data/spec/mongo/collection/view/change_stream_spec.rb +62 -3
- data/spec/mongo/collection/view/map_reduce_spec.rb +7 -5
- data/spec/mongo/collection/view/readable_spec.rb +4 -4
- data/spec/mongo/collection_spec.rb +331 -14
- data/spec/mongo/cursor_spec.rb +117 -5
- data/spec/mongo/database_spec.rb +240 -8
- data/spec/mongo/error/operation_failure_spec.rb +47 -1
- data/spec/mongo/error/parser_spec.rb +160 -23
- data/spec/mongo/operation/insert/bulk_spec.rb +2 -1
- data/spec/mongo/operation/result_spec.rb +27 -0
- data/spec/mongo/operation/update/bulk_spec.rb +1 -0
- data/spec/mongo/retryable_spec.rb +2 -0
- data/spec/mongo/server/app_metadata_spec.rb +2 -2
- data/spec/mongo/server/connection_spec.rb +13 -17
- data/spec/mongo/server/monitor/connection_spec.rb +13 -10
- data/spec/mongo/server_selector_spec.rb +34 -2
- data/spec/mongo/session/session_pool_spec.rb +14 -3
- data/spec/mongo/session_spec.rb +3 -3
- data/spec/mongo/session_transaction_spec.rb +4 -3
- data/spec/mongo/socket/ssl_spec.rb +19 -5
- data/spec/mongo/socket_spec.rb +1 -62
- data/spec/mongo/uri/srv_protocol_spec.rb +14 -20
- data/spec/mongo/uri_option_parsing_spec.rb +94 -8
- data/spec/mongo/uri_spec.rb +23 -10
- data/spec/mongo/write_concern_spec.rb +56 -3
- data/spec/spec_tests/change_streams_spec.rb +2 -1
- data/spec/spec_tests/cmap_spec.rb +1 -1
- data/spec/spec_tests/crud_spec.rb +12 -2
- data/spec/spec_tests/data/change_streams/change-streams-errors.yml +24 -1
- data/spec/spec_tests/data/change_streams/change-streams.yml +172 -3
- data/spec/spec_tests/data/command_monitoring/bulkWrite.yml +1 -1
- data/spec/spec_tests/data/command_monitoring/updateMany.yml +0 -2
- data/spec/spec_tests/data/command_monitoring/updateOne.yml +0 -5
- data/spec/spec_tests/data/crud/read/aggregate-out.yml +0 -6
- data/spec/spec_tests/data/crud/read/count-empty.yml +29 -0
- data/spec/spec_tests/data/crud/write/bulkWrite-arrayFilters.yml +1 -0
- data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +101 -0
- data/spec/spec_tests/data/crud/write/bulkWrite.yml +401 -0
- data/spec/spec_tests/data/crud/write/insertMany.yml +58 -2
- data/spec/spec_tests/data/crud/write/updateMany-arrayFilters.yml +3 -0
- data/spec/spec_tests/data/crud/write/updateOne-arrayFilters.yml +6 -1
- data/spec/spec_tests/data/crud_v2/aggregate-merge.yml +103 -0
- data/spec/spec_tests/data/crud_v2/aggregate-out-readConcern.yml +110 -0
- data/spec/spec_tests/data/crud_v2/bulkWrite-arrayFilters.yml +81 -0
- data/spec/spec_tests/data/crud_v2/db-aggregate.yml +38 -0
- data/spec/spec_tests/data/crud_v2/updateWithPipelines.yml +92 -0
- data/spec/spec_tests/data/retryable_writes/insertOne-serverErrors.yml +2 -2
- data/spec/spec_tests/data/transactions/abort.yml +3 -0
- data/spec/spec_tests/data/transactions/bulk.yml +3 -8
- data/spec/spec_tests/data/transactions/causal-consistency.yml +3 -8
- data/spec/spec_tests/data/transactions/commit.yml +3 -1
- data/spec/spec_tests/data/transactions/count.yml +3 -0
- data/spec/spec_tests/data/transactions/delete.yml +3 -0
- data/spec/spec_tests/data/transactions/error-labels.yml +4 -1
- data/spec/spec_tests/data/transactions/errors-client.yml +56 -0
- data/spec/spec_tests/data/transactions/errors.yml +3 -0
- data/spec/spec_tests/data/transactions/findOneAndDelete.yml +3 -0
- data/spec/spec_tests/data/transactions/findOneAndReplace.yml +3 -0
- data/spec/spec_tests/data/transactions/findOneAndUpdate.yml +3 -0
- data/spec/spec_tests/data/transactions/insert.yml +3 -0
- data/spec/spec_tests/data/transactions/isolation.yml +3 -0
- data/spec/spec_tests/data/transactions/mongos-pin-auto.yml +1671 -0
- data/spec/spec_tests/data/transactions/mongos-recovery-token.yml +347 -0
- data/spec/spec_tests/data/transactions/pin-mongos.yml +557 -0
- data/spec/spec_tests/data/transactions/read-concern.yml +3 -0
- data/spec/spec_tests/data/transactions/read-pref.yml +3 -0
- data/spec/spec_tests/data/transactions/reads.yml +3 -0
- data/spec/spec_tests/data/transactions/retryable-abort.yml +5 -2
- data/spec/spec_tests/data/transactions/retryable-commit.yml +4 -1
- data/spec/spec_tests/data/transactions/retryable-writes.yml +3 -0
- data/spec/spec_tests/data/transactions/run-command.yml +3 -0
- data/spec/spec_tests/data/transactions/transaction-options.yml +6 -0
- data/spec/spec_tests/data/transactions/update.yml +3 -8
- data/spec/spec_tests/data/transactions/write-concern.yml +348 -38
- data/spec/spec_tests/data/transactions_api/callback-aborts.yml +6 -0
- data/spec/spec_tests/data/transactions_api/callback-commits.yml +5 -0
- data/spec/spec_tests/data/transactions_api/callback-retry.yml +7 -2
- data/spec/spec_tests/data/transactions_api/commit-retry.yml +70 -15
- data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +3 -0
- data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +3 -0
- data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +59 -109
- data/spec/spec_tests/data/transactions_api/commit.yml +5 -0
- data/spec/spec_tests/data/transactions_api/transaction-options.yml +10 -0
- data/spec/spec_tests/retryable_reads_spec.rb +5 -2
- data/spec/spec_tests/retryable_writes_spec.rb +5 -2
- data/spec/spec_tests/sdam_monitoring_spec.rb +3 -3
- data/spec/spec_tests/sdam_spec.rb +2 -2
- data/spec/spec_tests/transactions_api_spec.rb +1 -67
- data/spec/spec_tests/transactions_spec.rb +2 -66
- data/spec/support/authorization.rb +4 -0
- data/spec/support/change_streams.rb +30 -10
- data/spec/support/change_streams/operation.rb +27 -0
- data/spec/support/client_registry.rb +44 -25
- data/spec/support/cluster_config.rb +25 -14
- data/spec/support/cluster_tools.rb +32 -10
- data/spec/support/command_monitoring.rb +1 -1
- data/spec/support/common_shortcuts.rb +30 -0
- data/spec/support/connection_string.rb +8 -3
- data/spec/support/constraints.rb +34 -0
- data/spec/support/crud.rb +31 -16
- data/spec/support/crud/context.rb +23 -0
- data/spec/support/crud/operation.rb +311 -14
- data/spec/support/crud/spec.rb +2 -1
- data/spec/support/crud/test.rb +24 -27
- data/spec/support/crud/test_base.rb +22 -0
- data/spec/support/crud/verifier.rb +15 -1
- data/spec/support/event_subscriber.rb +12 -0
- data/spec/support/sdam_formatter_integration.rb +12 -6
- data/spec/support/shared/server_selector.rb +10 -0
- data/spec/support/shared/session.rb +13 -12
- data/spec/support/spec_config.rb +32 -22
- data/spec/support/spec_setup.rb +2 -2
- data/spec/support/transactions.rb +87 -0
- data/spec/support/transactions/context.rb +33 -0
- data/spec/support/transactions/operation.rb +99 -349
- data/spec/support/transactions/spec.rb +1 -3
- data/spec/support/transactions/test.rb +110 -49
- data/spec/support/utils.rb +74 -1
- metadata +52 -10
- metadata.gz.sig +0 -0
- data/spec/support/crud/read.rb +0 -265
- data/spec/support/crud/write.rb +0 -284
@@ -148,6 +148,52 @@ describe Mongo::Error::OperationFailure do
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
151
|
+
|
152
|
+
context 'when there is a non-resumable label' do
|
153
|
+
context 'getMore response' do
|
154
|
+
let(:error) { Mongo::Error::OperationFailure.new('no message',
|
155
|
+
Mongo::Operation::GetMore::Result.new([]),
|
156
|
+
:code => 91, :code_name => 'ShutdownInProgress',
|
157
|
+
:labels => ['NonResumableChangeStreamError']) }
|
158
|
+
|
159
|
+
it 'returns false' do
|
160
|
+
expect(error.change_stream_resumable?).to eql(false)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'not a getMore response' do
|
165
|
+
let(:error) { Mongo::Error::OperationFailure.new('no message', nil,
|
166
|
+
:code => 91, :code_name => 'ShutdownInProgress',
|
167
|
+
:labels => ['NonResumableChangeStreamError']) }
|
168
|
+
|
169
|
+
it 'returns false' do
|
170
|
+
expect(error.change_stream_resumable?).to eql(false)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'when there is another label' do
|
176
|
+
context 'getMore response' do
|
177
|
+
let(:error) { Mongo::Error::OperationFailure.new('no message',
|
178
|
+
Mongo::Operation::GetMore::Result.new([]),
|
179
|
+
:code => 91, :code_name => 'ShutdownInProgress',
|
180
|
+
:labels => %w(TransientTransactionError)) }
|
181
|
+
|
182
|
+
it 'returns true' do
|
183
|
+
expect(error.change_stream_resumable?).to eql(true)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'not a getMore response' do
|
188
|
+
let(:error) { Mongo::Error::OperationFailure.new('no message', nil,
|
189
|
+
:code => 91, :code_name => 'ShutdownInProgress',
|
190
|
+
:labels => %w(TransientTransactionError)) }
|
191
|
+
|
192
|
+
it 'returns false' do
|
193
|
+
expect(error.change_stream_resumable?).to eql(false)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
151
197
|
end
|
152
198
|
|
153
199
|
describe '#labels' do
|
@@ -210,7 +256,7 @@ describe Mongo::Error::OperationFailure do
|
|
210
256
|
context 'when the error has labels' do
|
211
257
|
|
212
258
|
let(:labels) do
|
213
|
-
|
259
|
+
%w(TransientTransactionError)
|
214
260
|
end
|
215
261
|
|
216
262
|
it 'has the correct labels' do
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongo::Error::Parser do
|
4
|
+
let(:parser) do
|
5
|
+
described_class.new(document)
|
6
|
+
end
|
4
7
|
|
5
8
|
describe '#message' do
|
6
9
|
|
7
|
-
let(:parser) do
|
8
|
-
described_class.new(document)
|
9
|
-
end
|
10
|
-
|
11
10
|
context 'when the document contains no error message' do
|
12
11
|
|
13
12
|
let(:document) do
|
@@ -97,9 +96,6 @@ describe Mongo::Error::Parser do
|
|
97
96
|
end
|
98
97
|
|
99
98
|
describe '#code' do
|
100
|
-
let(:parser) do
|
101
|
-
described_class.new(document)
|
102
|
-
end
|
103
99
|
|
104
100
|
context 'when document contains code and ok: 1' do
|
105
101
|
let(:document) do
|
@@ -172,12 +168,23 @@ describe Mongo::Error::Parser do
|
|
172
168
|
expect(parser.code).to be nil
|
173
169
|
end
|
174
170
|
end
|
171
|
+
|
172
|
+
context 'when both top level code and write concern code are present' do
|
173
|
+
|
174
|
+
let(:document) do
|
175
|
+
{ 'ok' => 0,
|
176
|
+
'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster',
|
177
|
+
'writeConcernError' => {
|
178
|
+
'code' => 100, 'errmsg' => 'Not enough data-bearing nodes' } }
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'returns top level code' do
|
182
|
+
expect(parser.code).to eq(10107)
|
183
|
+
end
|
184
|
+
end
|
175
185
|
end
|
176
186
|
|
177
187
|
describe '#code_name' do
|
178
|
-
let(:parser) do
|
179
|
-
described_class.new(document)
|
180
|
-
end
|
181
188
|
|
182
189
|
context 'when document contains code name and ok: 1' do
|
183
190
|
let(:document) do
|
@@ -251,13 +258,152 @@ describe Mongo::Error::Parser do
|
|
251
258
|
expect(parser.code_name).to be nil
|
252
259
|
end
|
253
260
|
end
|
261
|
+
|
262
|
+
context 'when both top level code and write concern code are present' do
|
263
|
+
|
264
|
+
let(:document) do
|
265
|
+
{ 'ok' => 0,
|
266
|
+
'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster',
|
267
|
+
'writeConcernError' => {
|
268
|
+
'code' => 100, 'errmsg' => 'Not enough data-bearing nodes' } }
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'returns top level code' do
|
272
|
+
expect(parser.code_name).to eq('NotMaster')
|
273
|
+
end
|
274
|
+
end
|
254
275
|
end
|
255
276
|
|
256
|
-
describe '#
|
257
|
-
|
258
|
-
|
277
|
+
describe '#write_concern_error?' do
|
278
|
+
context 'there is a write concern error' do
|
279
|
+
|
280
|
+
let(:document) do
|
281
|
+
{ 'ok' => 1,
|
282
|
+
'writeConcernError' => {
|
283
|
+
'code' => 100, 'errmsg' => 'Not enough data-bearing nodes' } }
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'is true' do
|
287
|
+
expect(parser.write_concern_error?).to be true
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
context 'there is no write concern error' do
|
292
|
+
|
293
|
+
let(:document) do
|
294
|
+
{ 'ok' => 0,
|
295
|
+
'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster',
|
296
|
+
}
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'is false' do
|
300
|
+
expect(parser.write_concern_error?).to be false
|
301
|
+
end
|
259
302
|
end
|
260
303
|
|
304
|
+
context 'there is a top level error and write concern error' do
|
305
|
+
|
306
|
+
let(:document) do
|
307
|
+
{ 'ok' => 0,
|
308
|
+
'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster',
|
309
|
+
'writeConcernError' => {
|
310
|
+
'code' => 100, 'errmsg' => 'Not enough data-bearing nodes' } }
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'is true' do
|
314
|
+
expect(parser.write_concern_error?).to be true
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe '#write_concern_error_code' do
|
320
|
+
context 'there is a write concern error' do
|
321
|
+
|
322
|
+
let(:document) do
|
323
|
+
{ 'ok' => 1,
|
324
|
+
'writeConcernError' => {
|
325
|
+
'code' => 100, 'errmsg' => 'Not enough data-bearing nodes' } }
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'is true' do
|
329
|
+
expect(parser.write_concern_error_code).to eq(100)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context 'there is no write concern error' do
|
334
|
+
|
335
|
+
let(:document) do
|
336
|
+
{ 'ok' => 0,
|
337
|
+
'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster',
|
338
|
+
}
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'is nil' do
|
342
|
+
expect(parser.write_concern_error_code).to be nil
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context 'there is a top level error and write concern error' do
|
347
|
+
|
348
|
+
let(:document) do
|
349
|
+
{ 'ok' => 0,
|
350
|
+
'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster',
|
351
|
+
'writeConcernError' => {
|
352
|
+
'code' => 100, 'errmsg' => 'Not enough data-bearing nodes' } }
|
353
|
+
end
|
354
|
+
|
355
|
+
it 'is true' do
|
356
|
+
expect(parser.write_concern_error_code).to eq(100)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
describe '#write_concern_error_code_name' do
|
362
|
+
context 'there is a write concern error' do
|
363
|
+
|
364
|
+
let(:document) do
|
365
|
+
{ 'ok' => 1,
|
366
|
+
'writeConcernError' => {
|
367
|
+
'code' => 100, 'codeName' => 'SomeCodeName',
|
368
|
+
'errmsg' => 'Not enough data-bearing nodes' } }
|
369
|
+
end
|
370
|
+
|
371
|
+
it 'is the code name' do
|
372
|
+
expect(parser.write_concern_error_code_name).to eq('SomeCodeName')
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
context 'there is no write concern error' do
|
377
|
+
|
378
|
+
let(:document) do
|
379
|
+
{ 'ok' => 0,
|
380
|
+
'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster',
|
381
|
+
}
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'is nil' do
|
385
|
+
expect(parser.write_concern_error_code_name).to be nil
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
context 'there is a top level error and write concern error' do
|
390
|
+
|
391
|
+
let(:document) do
|
392
|
+
{ 'ok' => 0,
|
393
|
+
'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster',
|
394
|
+
'writeConcernError' => {
|
395
|
+
'code' => 100, 'codeName' => 'SomeCodeName',
|
396
|
+
'errmsg' => 'Not enough data-bearing nodes' } }
|
397
|
+
end
|
398
|
+
|
399
|
+
it 'is the code name' do
|
400
|
+
expect(parser.write_concern_error_code_name).to eq('SomeCodeName')
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
describe '#document' do
|
406
|
+
|
261
407
|
let(:document) do
|
262
408
|
{ 'ok' => 0, 'errmsg' => 'not master', 'code' => 10107, 'codeName' => 'NotMaster' }
|
263
409
|
end
|
@@ -268,9 +414,6 @@ describe Mongo::Error::Parser do
|
|
268
414
|
end
|
269
415
|
|
270
416
|
describe '#replies' do
|
271
|
-
let(:parser) do
|
272
|
-
described_class.new(document)
|
273
|
-
end
|
274
417
|
|
275
418
|
context 'when there are no replies' do
|
276
419
|
let(:document) do
|
@@ -284,9 +427,6 @@ describe Mongo::Error::Parser do
|
|
284
427
|
end
|
285
428
|
|
286
429
|
describe '#labels' do
|
287
|
-
let(:parser) do
|
288
|
-
described_class.new(document)
|
289
|
-
end
|
290
430
|
|
291
431
|
let(:document) do
|
292
432
|
{
|
@@ -308,7 +448,7 @@ describe Mongo::Error::Parser do
|
|
308
448
|
|
309
449
|
context 'when there are labels' do
|
310
450
|
let(:labels) do
|
311
|
-
|
451
|
+
%w(TransientTransactionError)
|
312
452
|
end
|
313
453
|
|
314
454
|
it 'has the correct labels' do
|
@@ -318,9 +458,6 @@ describe Mongo::Error::Parser do
|
|
318
458
|
end
|
319
459
|
|
320
460
|
describe '#wtimeout' do
|
321
|
-
let(:parser) do
|
322
|
-
described_class.new(document)
|
323
|
-
end
|
324
461
|
|
325
462
|
context 'when document contains wtimeout' do
|
326
463
|
let(:document) do
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongo::Operation::Insert do
|
4
|
+
require_no_multi_shard
|
5
|
+
|
4
6
|
before do
|
5
7
|
begin
|
6
8
|
authorized_collection.delete_many
|
@@ -188,7 +190,6 @@ describe Mongo::Operation::Insert do
|
|
188
190
|
end
|
189
191
|
|
190
192
|
context 'when write concern is unacknowledged' do
|
191
|
-
|
192
193
|
let(:write_concern) do
|
193
194
|
Mongo::WriteConcern.get(w: 0)
|
194
195
|
end
|
@@ -261,6 +261,17 @@ describe Mongo::Operation::Result do
|
|
261
261
|
end
|
262
262
|
end
|
263
263
|
end
|
264
|
+
|
265
|
+
context 'when there is a write concern error' do
|
266
|
+
let(:documents) do
|
267
|
+
[{'ok' => 1.0, 'writeConcernError' => {
|
268
|
+
'code' => 91, 'errmsg' => 'Replication is being shut down'}}]
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'is false' do
|
272
|
+
expect(result).not_to be_successful
|
273
|
+
end
|
274
|
+
end
|
264
275
|
end
|
265
276
|
|
266
277
|
describe '#written_count' do
|
@@ -309,4 +320,20 @@ describe Mongo::Operation::Result do
|
|
309
320
|
expect(result).to be_a(Mongo::Operation::Result)
|
310
321
|
end
|
311
322
|
end
|
323
|
+
|
324
|
+
describe '#validate!' do
|
325
|
+
|
326
|
+
context 'when there is a write concern error' do
|
327
|
+
let(:documents) do
|
328
|
+
[{'ok' => 1.0, 'writeConcernError' => {
|
329
|
+
'code' => 91, 'errmsg' => 'Replication is being shut down'}}]
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'raises OperationFailure' do
|
333
|
+
expect do
|
334
|
+
result.validate!
|
335
|
+
end.to raise_error(Mongo::Error::OperationFailure, /Replication is being shut down \(91\)/)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
312
339
|
end
|
@@ -67,6 +67,8 @@ class ModernRetryableTestConsumer < LegacyRetryableTestConsumer
|
|
67
67
|
i = 1
|
68
68
|
allow(session).to receive(:next_txn_num) { i += 1 }
|
69
69
|
allow(session).to receive(:in_transaction?).and_return(false)
|
70
|
+
allow(session).to receive(:pinned_server)
|
71
|
+
allow(session).to receive(:starting_transaction?).and_return(false)
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
@@ -23,7 +23,7 @@ describe Mongo::Server::AppMetadata do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
after do
|
26
|
-
client.close
|
26
|
+
client.close(true)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'sets the app name' do
|
@@ -41,7 +41,7 @@ describe Mongo::Server::AppMetadata do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
after do
|
44
|
-
client.close
|
44
|
+
client.close(true)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'raises an error' do
|
@@ -757,42 +757,38 @@ describe Mongo::Server::Connection, retry: 3 do
|
|
757
757
|
end
|
758
758
|
end
|
759
759
|
|
760
|
-
context 'when a socket timeout is set
|
760
|
+
context 'when a socket timeout is set' do
|
761
761
|
|
762
762
|
let(:connection) do
|
763
763
|
described_class.new(server, socket_timeout: 10)
|
764
764
|
end
|
765
765
|
|
766
|
-
it '
|
766
|
+
it 'sets the timeout' do
|
767
767
|
expect(connection.timeout).to eq(10)
|
768
768
|
end
|
769
|
-
end
|
770
769
|
|
771
|
-
context 'when an operation never completes' do
|
772
770
|
let(:client) do
|
773
|
-
authorized_client.with(socket_timeout: 1.5
|
774
|
-
# Read retries would cause the reads to be attempted twice,
|
775
|
-
# thus making the find take twice as long to time out.
|
776
|
-
retry_reads: false, max_read_retries: 0)
|
771
|
+
authorized_client.with(socket_timeout: 1.5)
|
777
772
|
end
|
778
773
|
|
779
774
|
before do
|
780
|
-
|
775
|
+
authorized_collection.delete_many
|
776
|
+
authorized_collection.insert_one(a: 1)
|
781
777
|
end
|
782
778
|
|
783
|
-
it '
|
779
|
+
it 'raises a timeout when it expires' do
|
784
780
|
start = Time.now
|
785
781
|
begin
|
786
|
-
Timeout::timeout(1.5 +
|
782
|
+
Timeout::timeout(1.5 + 15) do
|
787
783
|
client[authorized_collection.name].find("$where" => "sleep(2000) || true").first
|
788
784
|
end
|
789
785
|
rescue => ex
|
790
786
|
end_time = Time.now
|
791
|
-
expect(ex).to be_a(
|
792
|
-
expect(ex.message).to
|
787
|
+
expect(ex).to be_a(Timeout::Error)
|
788
|
+
expect(ex.message).to eq("Took more than 1.5 seconds to receive data.")
|
793
789
|
end
|
794
|
-
#
|
795
|
-
expect(end_time - start).to be_within(
|
790
|
+
# Account for wait queue timeout (2s) and rescue
|
791
|
+
expect(end_time - start).to be_within(2.5).of(1.5)
|
796
792
|
end
|
797
793
|
|
798
794
|
context 'when the socket_timeout is negative' do
|
@@ -820,7 +816,7 @@ describe Mongo::Server::Connection, retry: 3 do
|
|
820
816
|
it 'raises a timeout error' do
|
821
817
|
expect {
|
822
818
|
reply
|
823
|
-
}.to raise_exception(
|
819
|
+
}.to raise_exception(Timeout::Error)
|
824
820
|
end
|
825
821
|
end
|
826
822
|
end
|
@@ -1001,7 +997,7 @@ describe Mongo::Server::Connection, retry: 3 do
|
|
1001
997
|
end
|
1002
998
|
|
1003
999
|
after do
|
1004
|
-
client.close
|
1000
|
+
client.close(true)
|
1005
1001
|
end
|
1006
1002
|
|
1007
1003
|
context 'when a connect_timeout is in the options' do
|