mongo 2.8.0 → 2.9.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/Rakefile +12 -0
- data/lib/mongo.rb +15 -1
- data/lib/mongo/address/ipv6.rb +0 -2
- data/lib/mongo/auth/scram/conversation.rb +0 -3
- data/lib/mongo/bulk_write/result_combiner.rb +12 -2
- data/lib/mongo/client.rb +59 -6
- data/lib/mongo/cluster.rb +19 -8
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +0 -2
- data/lib/mongo/cluster/reapers/socket_reaper.rb +12 -9
- data/lib/mongo/collection.rb +1 -1
- data/lib/mongo/collection/view/aggregation.rb +5 -1
- data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
- data/lib/mongo/collection/view/change_stream.rb +30 -10
- data/lib/mongo/collection/view/iterable.rb +13 -6
- data/lib/mongo/collection/view/map_reduce.rb +12 -10
- data/lib/mongo/collection/view/readable.rb +19 -14
- data/lib/mongo/cursor.rb +12 -8
- data/lib/mongo/database.rb +10 -7
- data/lib/mongo/database/view.rb +18 -11
- data/lib/mongo/error.rb +2 -2
- data/lib/mongo/error/connection_check_out_timeout.rb +49 -0
- data/lib/mongo/error/operation_failure.rb +9 -9
- data/lib/mongo/error/parser.rb +25 -3
- data/lib/mongo/error/pool_closed_error.rb +43 -0
- data/lib/mongo/error/sdam_error_detection.rb +18 -0
- data/lib/mongo/grid/file/chunk.rb +0 -2
- data/lib/mongo/grid/fs_bucket.rb +26 -12
- data/lib/mongo/grid/stream/read.rb +36 -21
- data/lib/mongo/index/view.rb +11 -7
- data/lib/mongo/logger.rb +0 -2
- data/lib/mongo/monitoring.rb +31 -0
- data/lib/mongo/monitoring/cmap_log_subscriber.rb +53 -0
- data/lib/mongo/monitoring/event.rb +1 -0
- data/lib/mongo/monitoring/event/cmap.rb +25 -0
- data/lib/mongo/monitoring/event/cmap/base.rb +28 -0
- data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +78 -0
- data/lib/mongo/monitoring/event/cmap/connection_check_out_started.rb +56 -0
- data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +63 -0
- data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +64 -0
- data/lib/mongo/monitoring/event/cmap/connection_closed.rb +103 -0
- data/lib/mongo/monitoring/event/cmap/connection_created.rb +64 -0
- data/lib/mongo/monitoring/event/cmap/connection_ready.rb +64 -0
- data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +57 -0
- data/lib/mongo/monitoring/event/cmap/pool_closed.rb +57 -0
- data/lib/mongo/monitoring/event/cmap/pool_created.rb +63 -0
- data/lib/mongo/monitoring/event/command_started.rb +12 -3
- data/lib/mongo/monitoring/publishable.rb +10 -2
- data/lib/mongo/operation.rb +0 -1
- data/lib/mongo/operation/find/legacy/result.rb +1 -0
- data/lib/mongo/operation/list_collections/result.rb +7 -1
- data/lib/mongo/operation/result.rb +10 -1
- data/lib/mongo/operation/shared/executable.rb +15 -0
- data/lib/mongo/operation/shared/result/use_legacy_error_parser.rb +29 -0
- data/lib/mongo/operation/shared/specifiable.rb +0 -16
- data/lib/mongo/operation/update/legacy/result.rb +1 -0
- data/lib/mongo/protocol/compressed.rb +0 -2
- data/lib/mongo/protocol/msg.rb +25 -2
- data/lib/mongo/retryable.rb +171 -33
- data/lib/mongo/server.rb +26 -7
- data/lib/mongo/server/app_metadata.rb +0 -2
- data/lib/mongo/server/connectable.rb +8 -2
- data/lib/mongo/server/connection.rb +83 -13
- data/lib/mongo/server/connection_base.rb +1 -1
- data/lib/mongo/server/connection_pool.rb +439 -43
- data/lib/mongo/server/monitor/connection.rb +4 -1
- data/lib/mongo/session.rb +37 -5
- data/lib/mongo/session/session_pool.rb +2 -2
- data/lib/mongo/socket.rb +0 -2
- data/lib/mongo/socket/ssl.rb +0 -2
- data/lib/mongo/uri.rb +127 -66
- data/lib/mongo/uri/srv_protocol.rb +35 -13
- data/lib/mongo/version.rb +1 -1
- data/spec/README.md +190 -63
- data/spec/integration/change_stream_spec.rb +64 -0
- data/spec/integration/command_spec.rb +0 -7
- data/spec/integration/error_detection_spec.rb +39 -0
- data/spec/integration/read_concern.rb +83 -0
- data/spec/integration/retryable_writes_spec.rb +6 -50
- data/spec/integration/sdam_error_handling_spec.rb +60 -7
- data/spec/integration/ssl_uri_options_spec.rb +24 -0
- data/spec/integration/step_down_spec.rb +197 -0
- data/spec/lite_spec_helper.rb +4 -0
- data/spec/mongo/client_construction_spec.rb +42 -17
- data/spec/mongo/client_spec.rb +32 -1
- data/spec/mongo/cluster/socket_reaper_spec.rb +2 -2
- data/spec/mongo/cluster_spec.rb +36 -2
- data/spec/mongo/collection/view/aggregation_spec.rb +2 -0
- data/spec/mongo/collection/view/change_stream_spec.rb +28 -28
- data/spec/mongo/collection/view/readable_spec.rb +1 -1
- data/spec/mongo/collection/view_spec.rb +3 -1
- data/spec/mongo/cursor_spec.rb +5 -5
- data/spec/mongo/error/parser_spec.rb +61 -1
- data/spec/mongo/grid/stream/read_spec.rb +2 -2
- data/spec/mongo/monitoring/event/cmap/connection_check_out_failed_spec.rb +23 -0
- data/spec/mongo/monitoring/event/cmap/connection_check_out_started_spec.rb +19 -0
- data/spec/mongo/monitoring/event/cmap/connection_checked_in_spec.rb +23 -0
- data/spec/mongo/monitoring/event/cmap/connection_checked_out_spec.rb +23 -0
- data/spec/mongo/monitoring/event/cmap/connection_closed_spec.rb +27 -0
- data/spec/mongo/monitoring/event/cmap/connection_created_spec.rb +24 -0
- data/spec/mongo/monitoring/event/cmap/connection_ready_spec.rb +24 -0
- data/spec/mongo/monitoring/event/cmap/pool_cleared_spec.rb +19 -0
- data/spec/mongo/monitoring/event/cmap/pool_closed_spec.rb +19 -0
- data/spec/mongo/monitoring/event/cmap/pool_created_spec.rb +26 -0
- data/spec/mongo/operation/delete/bulk_spec.rb +1 -6
- data/spec/mongo/operation/delete/command_spec.rb +1 -1
- data/spec/mongo/operation/delete/op_msg_spec.rb +1 -1
- data/spec/mongo/operation/delete_spec.rb +4 -4
- data/spec/mongo/operation/insert/bulk_spec.rb +1 -1
- data/spec/mongo/operation/insert/command_spec.rb +1 -1
- data/spec/mongo/operation/insert/op_msg_spec.rb +1 -1
- data/spec/mongo/operation/update/bulk_spec.rb +1 -1
- data/spec/mongo/operation/update/command_spec.rb +2 -2
- data/spec/mongo/operation/update/op_msg_spec.rb +2 -2
- data/spec/mongo/protocol/msg_spec.rb +11 -0
- data/spec/mongo/retryable_spec.rb +78 -25
- data/spec/mongo/server/connection_pool_spec.rb +661 -126
- data/spec/mongo/server/connection_spec.rb +55 -7
- data/spec/mongo/server_spec.rb +5 -0
- data/spec/mongo/uri/srv_protocol_spec.rb +135 -2
- data/spec/mongo/uri_option_parsing_spec.rb +511 -0
- data/spec/mongo/uri_spec.rb +42 -6
- data/spec/spec_helper.rb +1 -84
- data/spec/spec_tests/cmap_spec.rb +50 -0
- data/spec/spec_tests/command_monitoring_spec.rb +7 -18
- data/spec/spec_tests/crud_spec.rb +3 -49
- data/spec/spec_tests/data/cmap/connection-must-have-id.yml +21 -0
- data/spec/spec_tests/data/cmap/connection-must-order-ids.yml +21 -0
- data/spec/spec_tests/data/cmap/pool-checkin-destroy-closed.yml +24 -0
- data/spec/spec_tests/data/cmap/pool-checkin-destroy-stale.yml +24 -0
- data/spec/spec_tests/data/cmap/pool-checkin-make-available.yml +21 -0
- data/spec/spec_tests/data/cmap/pool-checkin.yml +18 -0
- data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +13 -0
- data/spec/spec_tests/data/cmap/pool-checkout-error-closed.yml +28 -0
- data/spec/spec_tests/data/cmap/pool-checkout-multiple.yml +34 -0
- data/spec/spec_tests/data/cmap/pool-checkout-no-idle.yml +31 -0
- data/spec/spec_tests/data/cmap/pool-checkout-no-stale.yml +29 -0
- data/spec/spec_tests/data/cmap/pool-close-destroy-conns.yml +26 -0
- data/spec/spec_tests/data/cmap/pool-close.yml +11 -0
- data/spec/spec_tests/data/cmap/pool-create-max-size.yml +56 -0
- data/spec/spec_tests/data/cmap/pool-create-min-size.yml +27 -0
- data/spec/spec_tests/data/cmap/pool-create-with-options.yml +20 -0
- data/spec/spec_tests/data/cmap/pool-create.yml +12 -0
- data/spec/spec_tests/data/cmap/wait-queue-fairness.yml +94 -0
- data/spec/spec_tests/data/cmap/wait-queue-timeout.yml +41 -0
- data/spec/spec_tests/data/retryable_reads/aggregate-serverErrors.yml +157 -0
- data/spec/spec_tests/data/retryable_reads/aggregate.yml +87 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch-serverErrors.yml +149 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch.yml +61 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch-serverErrors.yml +149 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch.yml +65 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch-serverErrors.yml +153 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch.yml +61 -0
- data/spec/spec_tests/data/retryable_reads/count-serverErrors.yml +150 -0
- data/spec/spec_tests/data/retryable_reads/count.yml +64 -0
- data/spec/spec_tests/data/retryable_reads/countDocuments-serverErrors.yml +150 -0
- data/spec/spec_tests/data/retryable_reads/countDocuments.yml +64 -0
- data/spec/spec_tests/data/retryable_reads/distinct-serverErrors.yml +156 -0
- data/spec/spec_tests/data/retryable_reads/distinct.yml +71 -0
- data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-serverErrors.yml +148 -0
- data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount.yml +62 -0
- data/spec/spec_tests/data/retryable_reads/find-serverErrors.yml +160 -0
- data/spec/spec_tests/data/retryable_reads/find.yml +86 -0
- data/spec/spec_tests/data/retryable_reads/findOne-serverErrors.yml +154 -0
- data/spec/spec_tests/data/retryable_reads/findOne.yml +68 -0
- data/spec/spec_tests/data/retryable_reads/gridfs-download-serverErrors.yml +173 -0
- data/spec/spec_tests/data/retryable_reads/gridfs-download.yml +79 -0
- data/spec/spec_tests/data/retryable_reads/gridfs-downloadByName-serverErrors.yml +174 -0
- data/spec/spec_tests/data/retryable_reads/gridfs-downloadByName.yml +79 -0
- data/spec/spec_tests/data/retryable_reads/listCollectionNames-serverErrors.yml +143 -0
- data/spec/spec_tests/data/retryable_reads/listCollectionNames.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listCollectionObjects-serverErrors.yml +144 -0
- data/spec/spec_tests/data/retryable_reads/listCollectionObjects.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listCollections-serverErrors.yml +143 -0
- data/spec/spec_tests/data/retryable_reads/listCollections.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listDatabaseNames-serverErrors.yml +143 -0
- data/spec/spec_tests/data/retryable_reads/listDatabaseNames.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listDatabaseObjects-serverErrors.yml +144 -0
- data/spec/spec_tests/data/retryable_reads/listDatabaseObjects.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listDatabases-serverErrors.yml +144 -0
- data/spec/spec_tests/data/retryable_reads/listDatabases.yml +59 -0
- data/spec/spec_tests/data/retryable_reads/listIndexNames-serverErrors.yml +144 -0
- data/spec/spec_tests/data/retryable_reads/listIndexNames.yml +60 -0
- data/spec/spec_tests/data/retryable_reads/listIndexes-serverErrors.yml +145 -0
- data/spec/spec_tests/data/retryable_reads/listIndexes.yml +60 -0
- data/spec/spec_tests/data/retryable_reads/mapReduce.yml +60 -0
- data/spec/spec_tests/data/retryable_writes/bulkWrite-serverErrors.yml +10 -7
- data/spec/spec_tests/data/retryable_writes/bulkWrite.yml +15 -22
- data/spec/spec_tests/data/retryable_writes/deleteMany.yml +22 -0
- data/spec/spec_tests/data/retryable_writes/deleteOne-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/deleteOne.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/findOneAndDelete-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/findOneAndDelete.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/findOneAndReplace-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/findOneAndReplace.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/findOneAndUpdate-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/findOneAndUpdate.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/insertMany-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/insertMany.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/insertOne-serverErrors.yml +10 -45
- data/spec/spec_tests/data/retryable_writes/insertOne.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/replaceOne-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/replaceOne.yml +5 -8
- data/spec/spec_tests/data/retryable_writes/updateMany.yml +27 -0
- data/spec/spec_tests/data/retryable_writes/updateOne-serverErrors.yml +8 -7
- data/spec/spec_tests/data/retryable_writes/updateOne.yml +5 -14
- data/spec/spec_tests/data/transactions/abort.yml +7 -2
- data/spec/spec_tests/data/transactions/bulk.yml +7 -2
- data/spec/spec_tests/data/transactions/causal-consistency.yml +11 -4
- data/spec/spec_tests/data/transactions/commit.yml +11 -4
- data/spec/spec_tests/data/transactions/count.yml +64 -0
- data/spec/spec_tests/data/transactions/delete.yml +7 -2
- data/spec/spec_tests/data/transactions/error-labels.yml +8 -2
- data/spec/spec_tests/data/transactions/errors.yml +7 -2
- data/spec/spec_tests/data/transactions/findOneAndDelete.yml +7 -2
- data/spec/spec_tests/data/transactions/findOneAndReplace.yml +7 -2
- data/spec/spec_tests/data/transactions/findOneAndUpdate.yml +7 -2
- data/spec/spec_tests/data/transactions/insert.yml +9 -2
- data/spec/spec_tests/data/transactions/isolation.yml +7 -2
- data/spec/spec_tests/data/transactions/read-concern.yml +15 -6
- data/spec/spec_tests/data/transactions/read-pref.yml +7 -2
- data/spec/spec_tests/data/transactions/reads.yml +8 -48
- data/spec/spec_tests/data/transactions/retryable-abort.yml +7 -2
- data/spec/spec_tests/data/transactions/retryable-commit.yml +7 -2
- data/spec/spec_tests/data/transactions/retryable-writes.yml +7 -2
- data/spec/spec_tests/data/transactions/run-command.yml +7 -2
- data/spec/spec_tests/data/transactions/transaction-options.yml +7 -2
- data/spec/spec_tests/data/transactions/update.yml +7 -2
- data/spec/spec_tests/data/transactions/write-concern.yml +7 -2
- data/spec/spec_tests/data/transactions_api/callback-aborts.yml +6 -1
- data/spec/spec_tests/data/transactions_api/callback-commits.yml +6 -1
- data/spec/spec_tests/data/transactions_api/callback-retry.yml +6 -1
- data/spec/spec_tests/data/transactions_api/commit-retry.yml +6 -1
- data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +6 -3
- data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +6 -1
- data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +6 -1
- data/spec/spec_tests/data/transactions_api/commit.yml +6 -1
- data/spec/spec_tests/data/transactions_api/transaction-options.yml +6 -1
- data/spec/spec_tests/retryable_reads_spec.rb +11 -0
- data/spec/spec_tests/retryable_writes_spec.rb +4 -69
- data/spec/spec_tests/transactions_api_spec.rb +42 -37
- data/spec/spec_tests/transactions_spec.rb +42 -33
- data/spec/support/authorization.rb +12 -0
- data/spec/support/change_streams/operation.rb +1 -1
- data/spec/support/client_registry.rb +20 -0
- data/spec/support/cluster_config.rb +16 -15
- data/spec/support/cluster_tools.rb +346 -0
- data/spec/support/cmap.rb +367 -0
- data/spec/support/cmap/verifier.rb +46 -0
- data/spec/support/command_monitoring.rb +4 -6
- data/spec/support/common_shortcuts.rb +6 -0
- data/spec/support/connection_string.rb +2 -2
- data/spec/support/crud.rb +171 -184
- data/spec/support/crud/operation.rb +43 -0
- data/spec/support/crud/outcome.rb +53 -0
- data/spec/support/crud/read.rb +102 -12
- data/spec/support/crud/requirement.rb +69 -0
- data/spec/support/crud/spec.rb +68 -0
- data/spec/support/crud/test.rb +141 -0
- data/spec/support/crud/verifier.rb +96 -18
- data/spec/support/crud/write.rb +18 -3
- data/spec/support/event_subscriber.rb +15 -0
- data/spec/support/primary_socket.rb +2 -2
- data/spec/support/spec_config.rb +89 -20
- data/spec/support/transactions.rb +2 -306
- data/spec/support/transactions/operation.rb +7 -7
- data/spec/support/transactions/spec.rb +28 -0
- data/spec/support/transactions/test.rb +191 -0
- data/spec/support/utils.rb +123 -0
- metadata +202 -9
- metadata.gz.sig +0 -0
- data/lib/mongo/server/connection_pool/queue.rb +0 -359
- data/spec/mongo/server/connection_pool/queue_spec.rb +0 -353
- data/spec/support/transactions/verifier.rb +0 -97
@@ -25,9 +25,9 @@ describe 'Retryable writes integration tests' do
|
|
25
25
|
|
26
26
|
let(:primary_connection) do
|
27
27
|
client.database.command(ping: 1)
|
28
|
-
expect(primary_server.pool.
|
29
|
-
expect(primary_server.pool.
|
30
|
-
primary_server.pool.
|
28
|
+
expect(primary_server.pool.size).to eq(1)
|
29
|
+
expect(primary_server.pool.available_count).to eq(1)
|
30
|
+
primary_server.pool.instance_variable_get('@available_connections').last
|
31
31
|
end
|
32
32
|
|
33
33
|
shared_examples_for 'an operation that is retried' do
|
@@ -284,7 +284,7 @@ describe 'Retryable writes integration tests' do
|
|
284
284
|
end
|
285
285
|
|
286
286
|
let!(:collection) do
|
287
|
-
client[TEST_COLL
|
287
|
+
client[TEST_COLL]
|
288
288
|
end
|
289
289
|
|
290
290
|
before do
|
@@ -341,7 +341,7 @@ describe 'Retryable writes integration tests' do
|
|
341
341
|
context 'when the collection has write concern acknowledged' do
|
342
342
|
|
343
343
|
let!(:collection) do
|
344
|
-
client[TEST_COLL, write:
|
344
|
+
client[TEST_COLL, write: {w: :majority}]
|
345
345
|
end
|
346
346
|
|
347
347
|
it_behaves_like 'operation that is retried when server supports retryable writes'
|
@@ -355,15 +355,6 @@ describe 'Retryable writes integration tests' do
|
|
355
355
|
|
356
356
|
it_behaves_like 'an operation that is not retried'
|
357
357
|
end
|
358
|
-
|
359
|
-
context 'when the collection has write concern not set' do
|
360
|
-
|
361
|
-
let!(:collection) do
|
362
|
-
client[TEST_COLL]
|
363
|
-
end
|
364
|
-
|
365
|
-
it_behaves_like 'operation that is retried when server supports retryable writes'
|
366
|
-
end
|
367
358
|
end
|
368
359
|
|
369
360
|
context 'when the client has retry_writes set to false' do
|
@@ -375,42 +366,7 @@ describe 'Retryable writes integration tests' do
|
|
375
366
|
context 'when the collection has write concern acknowledged' do
|
376
367
|
|
377
368
|
let!(:collection) do
|
378
|
-
client[TEST_COLL, write:
|
379
|
-
end
|
380
|
-
|
381
|
-
it_behaves_like 'an operation that is not retried'
|
382
|
-
end
|
383
|
-
|
384
|
-
context 'when the collection has write concern unacknowledged' do
|
385
|
-
|
386
|
-
let!(:collection) do
|
387
|
-
client[TEST_COLL, write: { w: 0 }]
|
388
|
-
end
|
389
|
-
|
390
|
-
it_behaves_like 'an operation that is not retried'
|
391
|
-
end
|
392
|
-
|
393
|
-
context 'when the collection has write concern not set' do
|
394
|
-
|
395
|
-
let!(:collection) do
|
396
|
-
client[TEST_COLL]
|
397
|
-
end
|
398
|
-
|
399
|
-
it_behaves_like 'an operation that is not retried'
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
context 'when the client has retry_writes not set' do
|
404
|
-
require_no_retry_writes
|
405
|
-
|
406
|
-
let!(:client) do
|
407
|
-
authorized_client
|
408
|
-
end
|
409
|
-
|
410
|
-
context 'when the collection has write concern acknowledged' do
|
411
|
-
|
412
|
-
let!(:collection) do
|
413
|
-
client[TEST_COLL, write: SpecConfig.instance.write_concern]
|
369
|
+
client[TEST_COLL, write: {w: :majority}]
|
414
370
|
end
|
415
371
|
|
416
372
|
it_behaves_like 'an operation that is not retried'
|
@@ -6,7 +6,7 @@ describe 'SDAM error handling' do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe 'when there is an error during an operation' do
|
9
|
-
let(:client) {
|
9
|
+
let(:client) { authorized_client_without_any_retries }
|
10
10
|
|
11
11
|
before do
|
12
12
|
wait_for_all_servers(client.cluster)
|
@@ -58,6 +58,47 @@ describe 'SDAM error handling' do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
shared_examples_for 'clears connection pool' do
|
62
|
+
it 'clears connection pool' do
|
63
|
+
generation = server.pool.generation
|
64
|
+
operation
|
65
|
+
new_generation = server.pool.generation
|
66
|
+
expect(new_generation).to eq(generation + 1)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
shared_examples_for 'does not clear connection pool' do
|
71
|
+
it 'does not clear connection pool' do
|
72
|
+
generation = server.pool.generation
|
73
|
+
operation
|
74
|
+
new_generation = server.pool.generation
|
75
|
+
expect(new_generation).to eq(generation)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
shared_examples_for 'not master or node recovering' do
|
80
|
+
it_behaves_like 'marks server unknown'
|
81
|
+
it_behaves_like 'requests server scan'
|
82
|
+
|
83
|
+
context 'server 4.2 or higher' do
|
84
|
+
min_server_fcv '4.2'
|
85
|
+
|
86
|
+
it_behaves_like 'does not clear connection pool'
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'server 4.0 or lower' do
|
90
|
+
max_server_version '4.0'
|
91
|
+
|
92
|
+
it_behaves_like 'clears connection pool'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
shared_examples_for 'node shutting down' do
|
97
|
+
it_behaves_like 'marks server unknown'
|
98
|
+
it_behaves_like 'requests server scan'
|
99
|
+
it_behaves_like 'clears connection pool'
|
100
|
+
end
|
101
|
+
|
61
102
|
context 'not master error' do
|
62
103
|
let(:exception_message) do
|
63
104
|
/not master/
|
@@ -67,21 +108,31 @@ describe 'SDAM error handling' do
|
|
67
108
|
make_not_master_reply
|
68
109
|
end
|
69
110
|
|
70
|
-
it_behaves_like '
|
71
|
-
it_behaves_like 'requests server scan'
|
111
|
+
it_behaves_like 'not master or node recovering'
|
72
112
|
end
|
73
113
|
|
74
|
-
context 'node
|
114
|
+
context 'node recovering error' do
|
75
115
|
let(:exception_message) do
|
76
|
-
/
|
116
|
+
/DueToStepDown/
|
77
117
|
end
|
78
118
|
|
79
119
|
let(:reply) do
|
80
120
|
make_node_recovering_reply
|
81
121
|
end
|
82
122
|
|
83
|
-
it_behaves_like '
|
84
|
-
|
123
|
+
it_behaves_like 'not master or node recovering'
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'node shutting down error' do
|
127
|
+
let(:exception_message) do
|
128
|
+
/shutdown in progress/
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:reply) do
|
132
|
+
make_node_shutting_down_reply
|
133
|
+
end
|
134
|
+
|
135
|
+
it_behaves_like 'node shutting down'
|
85
136
|
end
|
86
137
|
|
87
138
|
context 'network error' do
|
@@ -100,6 +151,7 @@ describe 'SDAM error handling' do
|
|
100
151
|
|
101
152
|
it_behaves_like 'marks server unknown'
|
102
153
|
it_behaves_like 'does not request server scan'
|
154
|
+
it_behaves_like 'clears connection pool'
|
103
155
|
end
|
104
156
|
|
105
157
|
context 'network timeout error' do
|
@@ -109,6 +161,7 @@ describe 'SDAM error handling' do
|
|
109
161
|
|
110
162
|
it_behaves_like 'does not mark server unknown'
|
111
163
|
it_behaves_like 'does not request server scan'
|
164
|
+
it_behaves_like 'does not clear connection pool'
|
112
165
|
end
|
113
166
|
end
|
114
167
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'SSL connections with URI options' do
|
4
|
+
# SpecConfig currently creates clients exclusively through non-URI options. Because we don't
|
5
|
+
# currently have a way to create what the URI would look like for a given client, it's simpler
|
6
|
+
# just to test the that TLS works when configured from a URI on a standalone server without auth
|
7
|
+
# required, since that allows us to build the URI more easily.
|
8
|
+
require_no_auth
|
9
|
+
require_topology :single
|
10
|
+
require_ssl
|
11
|
+
|
12
|
+
let(:hosts) do
|
13
|
+
SpecConfig.instance.addresses.join(',')
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:uri) do
|
17
|
+
"mongodb://#{hosts}/?tls=true&tlsInsecure=true&tlsCertificateKeyFile=#{SpecConfig.instance.client_cert_key_pem}"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'successfully connects and runs an operation' do
|
21
|
+
client = Mongo::Client.new(uri)
|
22
|
+
expect { client[:foo].count_documents({}) }.not_to raise_error
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Step down behavior' do
|
4
|
+
require_topology :replica_set
|
5
|
+
|
6
|
+
=begin Uncommenting this will reduce the runtime of the test, but the spec currently does not allow us to do it
|
7
|
+
before(:all) do
|
8
|
+
# These before/after blocks are run even if the tests themselves are
|
9
|
+
# skipped due to server version not being appropriate
|
10
|
+
if ClusterConfig.instance.fcv_ish >= '4.2' && ClusterConfig.instance.topology == :replica_set
|
11
|
+
ClusterTools.instance.set_election_timeout(1)
|
12
|
+
ClusterTools.instance.set_election_handoff(false)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:all) do
|
17
|
+
if ClusterConfig.instance.fcv_ish >= '4.2' && ClusterConfig.instance.topology == :replica_set
|
18
|
+
ClusterTools.instance.set_election_timeout(10)
|
19
|
+
ClusterTools.instance.set_election_handoff(true)
|
20
|
+
ClusterTools.instance.reset_priorities
|
21
|
+
end
|
22
|
+
end
|
23
|
+
=end
|
24
|
+
|
25
|
+
let(:event_subscriber) { EventSubscriber.new }
|
26
|
+
|
27
|
+
let(:test_client) do
|
28
|
+
authorized_client_without_any_retries.with(server_selection_timeout: 20).tap do |client|
|
29
|
+
client.subscribe(Mongo::Monitoring::CONNECTION_POOL, event_subscriber)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:collection) { test_client['step-down'].with(write: write_concern) }
|
34
|
+
|
35
|
+
let(:admin_support_client) do
|
36
|
+
ClientRegistry.instance.global_client('root_authorized').use('admin')
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'getMore iteration' do
|
40
|
+
min_server_fcv '4.2'
|
41
|
+
|
42
|
+
let(:subscribed_client) do
|
43
|
+
test_client.tap do |client|
|
44
|
+
client.subscribe(Mongo::Monitoring::COMMAND, EventSubscriber)
|
45
|
+
client.subscribe(Mongo::Monitoring::CONNECTION_POOL, EventSubscriber)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:collection) { subscribed_client['step-down'] }
|
50
|
+
|
51
|
+
before do
|
52
|
+
collection.insert_many([{test: 1}] * 100)
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:view) { collection.find({test: 1}, batch_size: 10) }
|
56
|
+
let(:enum) { view.to_enum }
|
57
|
+
|
58
|
+
it 'continues through step down' do
|
59
|
+
|
60
|
+
subscribed_client.cluster.next_primary.pool.clear
|
61
|
+
event_subscriber.clear_events!
|
62
|
+
|
63
|
+
# get the first item
|
64
|
+
item = enum.next
|
65
|
+
expect(item['test']).to eq(1)
|
66
|
+
|
67
|
+
connection_created_events = EventSubscriber.published_events.select do |event|
|
68
|
+
event.is_a?(Mongo::Monitoring::Event::Cmap::ConnectionCreated)
|
69
|
+
end
|
70
|
+
expect(connection_created_events).not_to be_empty
|
71
|
+
|
72
|
+
current_primary = subscribed_client.cluster.next_primary
|
73
|
+
ClusterTools.instance.force_step_down
|
74
|
+
|
75
|
+
EventSubscriber.clear_events!
|
76
|
+
|
77
|
+
# exhaust the batch
|
78
|
+
9.times do
|
79
|
+
enum.next
|
80
|
+
end
|
81
|
+
|
82
|
+
# this should issue a getMore
|
83
|
+
item = enum.next
|
84
|
+
expect(item['test']).to eq(1)
|
85
|
+
|
86
|
+
get_more_events = EventSubscriber.started_events.select do |event|
|
87
|
+
event.command['getMore']
|
88
|
+
end
|
89
|
+
|
90
|
+
expect(get_more_events.length).to eq(1)
|
91
|
+
|
92
|
+
# getMore should have been sent on the same connection as find
|
93
|
+
connection_created_events = EventSubscriber.published_events.select do |event|
|
94
|
+
event.is_a?(Mongo::Monitoring::Event::Cmap::ConnectionCreated)
|
95
|
+
end
|
96
|
+
expect(connection_created_events).to be_empty
|
97
|
+
end
|
98
|
+
|
99
|
+
after do
|
100
|
+
# The tests normally operate with a low server selection timeout,
|
101
|
+
# but since this test caused a cluster election we may need to wait
|
102
|
+
# longer for the cluster to reestablish itself.
|
103
|
+
# To keep all other tests' timeouts low, wait for primary to be
|
104
|
+
# elected at the end of this test
|
105
|
+
test_client.cluster.servers.each do |server|
|
106
|
+
server.unknown!
|
107
|
+
end
|
108
|
+
test_client.cluster.next_primary
|
109
|
+
|
110
|
+
# Since we are changing which server is primary, close all clients
|
111
|
+
# to prevent subsequent tests setting fail points on servers which
|
112
|
+
# are not primary
|
113
|
+
ClientRegistry.instance.close_all_clients
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'writes on connections' do
|
118
|
+
min_server_fcv '4.0'
|
119
|
+
|
120
|
+
let(:server) do
|
121
|
+
client = test_client.with(app_name: rand)
|
122
|
+
client['test'].insert_one(test: 1)
|
123
|
+
client.cluster.next_primary
|
124
|
+
end
|
125
|
+
|
126
|
+
let(:fail_point) do
|
127
|
+
{ configureFailPoint: 'failCommand', data: {
|
128
|
+
# There is currently no way to turn write retries on not master
|
129
|
+
# errors off - therefore set the number of fails to 2
|
130
|
+
failCommands: ['insert'], errorCode: fail_point_code, }, mode: {times: 2} }
|
131
|
+
end
|
132
|
+
|
133
|
+
before do
|
134
|
+
collection.find
|
135
|
+
admin_support_client.command(fail_point)
|
136
|
+
end
|
137
|
+
|
138
|
+
after do
|
139
|
+
admin_support_client.command(configureFailPoint: 'failCommand', mode: 'off')
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'not master - 4.2' do
|
143
|
+
min_server_fcv '4.2'
|
144
|
+
|
145
|
+
let(:write_concern) { {:w => 1} }
|
146
|
+
|
147
|
+
# not master
|
148
|
+
let(:fail_point_code) { 10107 }
|
149
|
+
|
150
|
+
it 'keeps connection open' do
|
151
|
+
event_subscriber.clear_events!
|
152
|
+
|
153
|
+
expect do
|
154
|
+
collection.insert_one(test: 1)
|
155
|
+
end.to raise_error(Mongo::Error::OperationFailure, /10107/)
|
156
|
+
|
157
|
+
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(0)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe 'not master - 4.0' do
|
162
|
+
max_server_version '4.0'
|
163
|
+
|
164
|
+
let(:write_concern) { {:w => 1} }
|
165
|
+
|
166
|
+
# not master
|
167
|
+
let(:fail_point_code) { 10107 }
|
168
|
+
|
169
|
+
it 'closes the connection' do
|
170
|
+
event_subscriber.clear_events!
|
171
|
+
|
172
|
+
expect do
|
173
|
+
collection.insert_one(test: 1)
|
174
|
+
end.to raise_error(Mongo::Error::OperationFailure, /10107/)
|
175
|
+
|
176
|
+
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(1)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe 'node shutting down' do
|
181
|
+
let(:write_concern) { {:w => 1} }
|
182
|
+
|
183
|
+
# interrupted at shutdown
|
184
|
+
let(:fail_point_code) { 11600 }
|
185
|
+
|
186
|
+
it 'closes the connection' do
|
187
|
+
event_subscriber.clear_events!
|
188
|
+
|
189
|
+
expect do
|
190
|
+
collection.insert_one(test: 1)
|
191
|
+
end.to raise_error(Mongo::Error::OperationFailure, /11600/)
|
192
|
+
|
193
|
+
expect(event_subscriber.select_published_events(Mongo::Monitoring::Event::Cmap::PoolCleared).count).to eq(1)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
data/spec/lite_spec_helper.rb
CHANGED
@@ -7,6 +7,7 @@ SERVER_SELECTION_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/server_select
|
|
7
7
|
MAX_STALENESS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/max_staleness/**/*.yml")
|
8
8
|
CRUD_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/crud/**/*.yml")
|
9
9
|
RETRYABLE_WRITES_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/retryable_writes/**/*.yml")
|
10
|
+
RETRYABLE_READS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/retryable_reads/**/*.yml").sort
|
10
11
|
COMMAND_MONITORING_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/command_monitoring/**/*.yml")
|
11
12
|
CONNECTION_STRING_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/connection_string/*.yml")
|
12
13
|
URI_OPTIONS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/uri_options/*.yml")
|
@@ -15,6 +16,7 @@ GRIDFS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/gridfs/*.yml")
|
|
15
16
|
TRANSACTIONS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/transactions/*.yml")
|
16
17
|
TRANSACTIONS_API_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/transactions_api/*.yml")
|
17
18
|
CHANGE_STREAMS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/change_streams/*.yml")
|
19
|
+
CMAP_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/cmap/*.yml")
|
18
20
|
|
19
21
|
if ENV['DRIVERS_TOOLS']
|
20
22
|
CLIENT_CERT_PEM = ENV['DRIVER_TOOLS_CLIENT_CERT_PEM']
|
@@ -68,6 +70,7 @@ require 'support/server_selection'
|
|
68
70
|
require 'support/sdam_monitoring'
|
69
71
|
require 'support/crud'
|
70
72
|
require 'support/command_monitoring'
|
73
|
+
require 'support/cmap'
|
71
74
|
require 'support/connection_string'
|
72
75
|
require 'support/gridfs'
|
73
76
|
require 'support/transactions'
|
@@ -77,6 +80,7 @@ require 'support/client_registry'
|
|
77
80
|
require 'support/client_registry_macros'
|
78
81
|
require 'support/json_ext_formatter'
|
79
82
|
require 'support/sdam_formatter_integration'
|
83
|
+
require 'support/utils'
|
80
84
|
|
81
85
|
if SpecConfig.instance.mri?
|
82
86
|
require 'timeout_interrupt'
|