mongo 2.14.0 → 2.15.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +4 -1
- data/Rakefile +8 -15
- data/lib/mongo.rb +23 -0
- data/lib/mongo/auth/aws/conversation.rb +1 -4
- data/lib/mongo/auth/base.rb +13 -7
- data/lib/mongo/auth/conversation_base.rb +32 -0
- data/lib/mongo/auth/cr/conversation.rb +6 -29
- data/lib/mongo/auth/gssapi/conversation.rb +4 -15
- data/lib/mongo/auth/ldap/conversation.rb +3 -14
- data/lib/mongo/auth/sasl_conversation_base.rb +1 -13
- data/lib/mongo/auth/scram_conversation_base.rb +7 -34
- data/lib/mongo/auth/user/view.rb +16 -9
- data/lib/mongo/auth/x509/conversation.rb +4 -25
- data/lib/mongo/background_thread.rb +11 -0
- data/lib/mongo/bulk_write.rb +21 -18
- data/lib/mongo/client.rb +82 -6
- data/lib/mongo/cluster.rb +19 -28
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +6 -2
- data/lib/mongo/cluster/sdam_flow.rb +14 -0
- data/lib/mongo/collection.rb +8 -6
- data/lib/mongo/collection/view/aggregation.rb +1 -1
- data/lib/mongo/collection/view/change_stream.rb +1 -1
- data/lib/mongo/collection/view/iterable.rb +1 -1
- data/lib/mongo/collection/view/map_reduce.rb +2 -2
- data/lib/mongo/collection/view/readable.rb +42 -20
- data/lib/mongo/collection/view/writable.rb +14 -14
- data/lib/mongo/cursor.rb +2 -2
- data/lib/mongo/database.rb +22 -5
- data/lib/mongo/database/view.rb +1 -1
- data/lib/mongo/error.rb +9 -1
- data/lib/mongo/error/bulk_write_error.rb +17 -3
- data/lib/mongo/error/internal_driver_error.rb +22 -0
- data/lib/mongo/error/operation_failure.rb +21 -2
- data/lib/mongo/error/parser.rb +65 -12
- data/lib/mongo/error/server_api_conflict.rb +23 -0
- data/lib/mongo/error/server_api_not_supported.rb +24 -0
- data/lib/mongo/error/unmet_dependency.rb +21 -0
- data/lib/mongo/grid/fs_bucket.rb +37 -37
- data/lib/mongo/index/view.rb +21 -11
- data/lib/mongo/monitoring.rb +13 -4
- data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +27 -16
- data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +26 -15
- data/lib/mongo/operation.rb +2 -2
- data/lib/mongo/operation/collections_info.rb +18 -1
- data/lib/mongo/operation/collections_info/command.rb +2 -2
- data/lib/mongo/operation/context.rb +99 -0
- data/lib/mongo/operation/indexes.rb +15 -1
- data/lib/mongo/operation/insert/command.rb +2 -2
- data/lib/mongo/operation/insert/legacy.rb +2 -2
- data/lib/mongo/operation/insert/op_msg.rb +2 -2
- data/lib/mongo/operation/list_collections/result.rb +4 -1
- data/lib/mongo/operation/result.rb +2 -0
- data/lib/mongo/operation/shared/executable.rb +24 -14
- data/lib/mongo/operation/shared/executable_no_validate.rb +2 -2
- data/lib/mongo/operation/shared/op_msg_or_command.rb +1 -7
- data/lib/mongo/operation/shared/op_msg_or_find_command.rb +1 -7
- data/lib/mongo/operation/shared/polymorphic_operation.rb +39 -0
- data/lib/mongo/operation/shared/response_handling.rb +23 -23
- data/lib/mongo/operation/shared/sessions_supported.rb +13 -2
- data/lib/mongo/operation/shared/write.rb +8 -18
- data/lib/mongo/protocol/compressed.rb +51 -5
- data/lib/mongo/protocol/message.rb +20 -2
- data/lib/mongo/protocol/msg.rb +36 -11
- data/lib/mongo/query_cache.rb +30 -0
- data/lib/mongo/retryable.rb +1 -1
- data/lib/mongo/server.rb +7 -15
- data/lib/mongo/server/app_metadata.rb +52 -18
- data/lib/mongo/server/connection.rb +5 -0
- data/lib/mongo/server/connection_base.rb +13 -10
- data/lib/mongo/server/connection_pool.rb +6 -4
- data/lib/mongo/server/description.rb +4 -0
- data/lib/mongo/server/description/features.rb +9 -8
- data/lib/mongo/server/monitor.rb +20 -1
- data/lib/mongo/server/monitor/app_metadata.rb +1 -1
- data/lib/mongo/server/monitor/connection.rb +9 -10
- data/lib/mongo/server/pending_connection.rb +24 -6
- data/lib/mongo/server/push_monitor.rb +11 -1
- data/lib/mongo/session.rb +2 -2
- data/lib/mongo/session/session_pool.rb +4 -2
- data/lib/mongo/socket.rb +29 -4
- data/lib/mongo/socket/ssl.rb +8 -0
- data/lib/mongo/srv/monitor.rb +0 -11
- data/lib/mongo/uri/options_mapper.rb +38 -0
- data/lib/mongo/utils.rb +15 -0
- data/lib/mongo/version.rb +1 -1
- data/spec/README.md +24 -1
- data/spec/integration/auth_spec.rb +25 -15
- data/spec/integration/bulk_write_error_message_spec.rb +41 -0
- data/spec/integration/change_stream_spec.rb +4 -4
- data/spec/integration/command_monitoring_spec.rb +2 -2
- data/spec/integration/connection_spec.rb +2 -0
- data/spec/integration/docs_examples_spec.rb +8 -1
- data/spec/integration/fork_reconnect_spec.rb +4 -1
- data/spec/integration/ocsp_verifier_spec.rb +13 -7
- data/spec/integration/operation_failure_code_spec.rb +1 -1
- data/spec/integration/operation_failure_message_spec.rb +90 -0
- data/spec/integration/reconnect_spec.rb +1 -1
- data/spec/integration/sdam_error_handling_spec.rb +1 -1
- data/spec/integration/sdam_events_spec.rb +3 -5
- data/spec/integration/snappy_compression_spec.rb +25 -0
- data/spec/integration/srv_monitoring_spec.rb +1 -1
- data/spec/integration/transactions_examples_spec.rb +6 -0
- data/spec/integration/zlib_compression_spec.rb +1 -1
- data/spec/integration/zstd_compression_spec.rb +26 -0
- data/spec/lite_spec_helper.rb +7 -1
- data/spec/mongo/address_spec.rb +15 -11
- data/spec/mongo/auth/ldap/conversation_spec.rb +1 -1
- data/spec/mongo/auth/ldap_spec.rb +5 -1
- data/spec/mongo/auth/scram_negotiation_spec.rb +1 -1
- data/spec/mongo/auth/scram_spec.rb +1 -1
- data/spec/mongo/auth/x509/conversation_spec.rb +3 -3
- data/spec/mongo/client_construction_spec.rb +207 -33
- data/spec/mongo/client_spec.rb +17 -0
- data/spec/mongo/cluster_spec.rb +3 -18
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/readable_spec.rb +33 -19
- data/spec/mongo/collection_crud_spec.rb +4357 -0
- data/spec/mongo/collection_ddl_spec.rb +534 -0
- data/spec/mongo/collection_spec.rb +5 -4859
- data/spec/mongo/database_spec.rb +66 -4
- data/spec/mongo/error/bulk_write_error_spec.rb +3 -3
- data/spec/mongo/error/parser_spec.rb +37 -6
- data/spec/mongo/index/view_spec.rb +8 -2
- data/spec/mongo/monitoring/event/server_heartbeat_failed_spec.rb +1 -1
- data/spec/mongo/monitoring/event/server_heartbeat_succeeded_spec.rb +1 -1
- data/spec/mongo/operation/aggregate_spec.rb +2 -1
- data/spec/mongo/operation/collections_info_spec.rb +4 -1
- data/spec/mongo/operation/command_spec.rb +6 -3
- data/spec/mongo/operation/create_index_spec.rb +6 -3
- data/spec/mongo/operation/create_user_spec.rb +6 -3
- data/spec/mongo/operation/delete/bulk_spec.rb +9 -6
- data/spec/mongo/operation/delete_spec.rb +11 -7
- data/spec/mongo/operation/drop_index_spec.rb +6 -2
- data/spec/mongo/operation/find/legacy_spec.rb +3 -1
- data/spec/mongo/operation/get_more_spec.rb +3 -1
- data/spec/mongo/operation/indexes_spec.rb +5 -1
- data/spec/mongo/operation/insert/bulk_spec.rb +10 -7
- data/spec/mongo/operation/insert_spec.rb +15 -12
- data/spec/mongo/operation/map_reduce_spec.rb +5 -2
- data/spec/mongo/operation/remove_user_spec.rb +6 -3
- data/spec/mongo/operation/result_spec.rb +1 -1
- data/spec/mongo/operation/update/bulk_spec.rb +9 -6
- data/spec/mongo/operation/update_spec.rb +10 -7
- data/spec/mongo/operation/update_user_spec.rb +4 -1
- data/spec/mongo/protocol/compressed_spec.rb +26 -12
- data/spec/mongo/query_cache_middleware_spec.rb +55 -0
- data/spec/mongo/retryable_spec.rb +3 -2
- data/spec/mongo/server/app_metadata_spec.rb +2 -0
- data/spec/mongo/server/connection_pool/populator_spec.rb +3 -1
- data/spec/mongo/server/connection_pool_spec.rb +1 -1
- data/spec/mongo/server/connection_spec.rb +24 -17
- data/spec/mongo/server/monitor/connection_spec.rb +17 -7
- data/spec/mongo/server/monitor_spec.rb +9 -1
- data/spec/mongo/server_spec.rb +15 -2
- data/spec/mongo/socket/ssl_spec.rb +40 -0
- data/spec/mongo/socket_spec.rb +2 -2
- data/spec/mongo/tls_context_hooks_spec.rb +37 -0
- data/spec/runners/connection_string.rb +0 -4
- data/spec/runners/crud/requirement.rb +40 -3
- data/spec/runners/crud/verifier.rb +8 -0
- data/spec/runners/transactions/operation.rb +13 -2
- data/spec/runners/transactions/test.rb +1 -0
- data/spec/runners/unified.rb +96 -0
- data/spec/runners/unified/assertions.rb +249 -0
- data/spec/runners/unified/change_stream_operations.rb +26 -0
- data/spec/runners/unified/crud_operations.rb +199 -0
- data/spec/runners/unified/ddl_operations.rb +96 -0
- data/spec/runners/unified/entity_map.rb +39 -0
- data/spec/runners/unified/error.rb +25 -0
- data/spec/runners/unified/event_subscriber.rb +91 -0
- data/spec/runners/unified/exceptions.rb +21 -0
- data/spec/runners/unified/grid_fs_operations.rb +55 -0
- data/spec/runners/unified/support_operations.rb +250 -0
- data/spec/runners/unified/test.rb +393 -0
- data/spec/runners/unified/test_group.rb +28 -0
- data/spec/runners/unified/using_hash.rb +31 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/lib/mrss/cluster_config.rb +218 -0
- data/spec/shared/lib/mrss/constraints.rb +43 -0
- data/spec/shared/lib/mrss/docker_runner.rb +262 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +112 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +231 -0
- data/spec/shared/shlib/distro.sh +73 -0
- data/spec/shared/shlib/server.sh +290 -0
- data/spec/shared/shlib/set_env.sh +128 -0
- data/spec/solo/clean_exit_spec.rb +21 -0
- data/spec/spec_helper.rb +4 -1
- data/spec/spec_tests/crud_unified_spec.rb +10 -0
- data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
- data/spec/spec_tests/data/crud_unified/estimatedDocumentCount.yml +267 -0
- data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-4.9.yml +60 -0
- data/spec/spec_tests/data/retryable_reads/{estimatedDocumentCount.yml → estimatedDocumentCount-pre4.9.yml} +2 -0
- data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-serverErrors-4.9.yml +146 -0
- data/spec/spec_tests/data/retryable_reads/{estimatedDocumentCount-serverErrors.yml → estimatedDocumentCount-serverErrors-pre4.9.yml} +2 -0
- data/spec/spec_tests/data/retryable_reads/listIndexNames.yml +1 -1
- data/spec/spec_tests/data/unified/valid-fail/operation-failure.yml +31 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-change-streams.yml +220 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-command-monitoring.yml +102 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-crud.yml +184 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-gridfs.yml +155 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-retryable-reads.yml +193 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-retryable-writes.yml +210 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-sessions.yml +215 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-transactions-convenient-api.yml +235 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-transactions-mongos-pin-auto.yml +169 -0
- data/spec/spec_tests/data/unified/valid-pass/poc-transactions.yml +170 -0
- data/spec/spec_tests/data/uri_options/compression-options.yml +1 -1
- data/spec/spec_tests/data/versioned_api/crud-api-version-1-strict.yml +416 -0
- data/spec/spec_tests/data/versioned_api/crud-api-version-1.yml +409 -0
- data/spec/spec_tests/data/versioned_api/runcommand-helper-no-api-version-declared.yml +67 -0
- data/spec/spec_tests/data/versioned_api/test-commands-deprecation-errors.yml +47 -0
- data/spec/spec_tests/data/versioned_api/test-commands-strict-mode.yml +44 -0
- data/spec/spec_tests/data/versioned_api/transaction-handling.yml +180 -0
- data/spec/spec_tests/unified_spec.rb +15 -0
- data/spec/spec_tests/uri_options_spec.rb +16 -0
- data/spec/spec_tests/versioned_api_spec.rb +10 -0
- data/spec/support/common_shortcuts.rb +15 -1
- data/spec/support/shared/session.rb +2 -2
- data/spec/support/spec_config.rb +46 -3
- data/spec/support/spec_setup.rb +48 -38
- data/spec/support/utils.rb +64 -3
- metadata +1104 -992
- metadata.gz.sig +0 -0
- data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +0 -58
- data/lib/mongo/operation/shared/op_msg_or_list_indexes_command.rb +0 -47
- data/spec/support/cluster_config.rb +0 -207
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongo::Operation::Update do
|
4
|
+
require_no_required_api_version
|
5
|
+
|
6
|
+
let(:context) { Mongo::Operation::Context.new }
|
4
7
|
|
5
8
|
let(:document) do
|
6
9
|
{ :q => { :foo => 1 },
|
@@ -100,7 +103,7 @@ describe Mongo::Operation::Update do
|
|
100
103
|
end
|
101
104
|
|
102
105
|
let(:result) do
|
103
|
-
update.execute(authorized_primary,
|
106
|
+
update.execute(authorized_primary, context: context)
|
104
107
|
end
|
105
108
|
|
106
109
|
it 'updates the document' do
|
@@ -128,7 +131,7 @@ describe Mongo::Operation::Update do
|
|
128
131
|
|
129
132
|
it 'raises an exception' do
|
130
133
|
expect {
|
131
|
-
update.execute(authorized_primary,
|
134
|
+
update.execute(authorized_primary, context: context)
|
132
135
|
}.to raise_error(Mongo::Error::OperationFailure)
|
133
136
|
end
|
134
137
|
end
|
@@ -152,7 +155,7 @@ describe Mongo::Operation::Update do
|
|
152
155
|
end
|
153
156
|
|
154
157
|
let(:result) do
|
155
|
-
update.execute(authorized_primary,
|
158
|
+
update.execute(authorized_primary, context: context)
|
156
159
|
end
|
157
160
|
|
158
161
|
it 'updates the documents' do
|
@@ -180,7 +183,7 @@ describe Mongo::Operation::Update do
|
|
180
183
|
|
181
184
|
it 'raises an exception' do
|
182
185
|
expect {
|
183
|
-
update.execute(authorized_primary,
|
186
|
+
update.execute(authorized_primary, context: context)
|
184
187
|
}.to raise_error(Mongo::Error::OperationFailure)
|
185
188
|
end
|
186
189
|
end
|
@@ -193,7 +196,7 @@ describe Mongo::Operation::Update do
|
|
193
196
|
|
194
197
|
it 'raises an error' do
|
195
198
|
expect {
|
196
|
-
update.execute(authorized_primary,
|
199
|
+
update.execute(authorized_primary, context: context)
|
197
200
|
}.to raise_error(Mongo::Error::MaxBSONSize)
|
198
201
|
end
|
199
202
|
end
|
@@ -205,7 +208,7 @@ describe Mongo::Operation::Update do
|
|
205
208
|
end
|
206
209
|
|
207
210
|
let(:result) do
|
208
|
-
update.execute(authorized_primary,
|
211
|
+
update.execute(authorized_primary, context: context)
|
209
212
|
end
|
210
213
|
|
211
214
|
it 'inserts the document' do
|
@@ -243,7 +246,7 @@ describe Mongo::Operation::Update do
|
|
243
246
|
end
|
244
247
|
|
245
248
|
let(:result) do
|
246
|
-
update.execute(authorized_primary,
|
249
|
+
update.execute(authorized_primary, context: context)
|
247
250
|
end
|
248
251
|
|
249
252
|
before do
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongo::Operation::UpdateUser do
|
4
|
+
require_no_required_api_version
|
5
|
+
|
6
|
+
let(:context) { Mongo::Operation::Context.new }
|
4
7
|
|
5
8
|
describe '#execute' do
|
6
9
|
|
@@ -35,7 +38,7 @@ describe Mongo::Operation::UpdateUser do
|
|
35
38
|
context 'when user update was successful' do
|
36
39
|
|
37
40
|
let!(:response) do
|
38
|
-
operation.execute(root_authorized_primary,
|
41
|
+
operation.execute(root_authorized_primary, context: context)
|
39
42
|
end
|
40
43
|
|
41
44
|
it 'updates the user in the database' do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongo::Protocol::Compressed do
|
4
4
|
|
@@ -10,15 +10,35 @@ describe Mongo::Protocol::Compressed do
|
|
10
10
|
described_class.new(original_message, compressor, level)
|
11
11
|
end
|
12
12
|
|
13
|
+
let(:original_message_bytes) do
|
14
|
+
buf = BSON::ByteBuffer.new
|
15
|
+
original_message.send(:serialize_fields, buf)
|
16
|
+
buf.to_s
|
17
|
+
end
|
18
|
+
|
13
19
|
describe '#serialize' do
|
14
20
|
|
15
|
-
context
|
21
|
+
context "when using the snappy compressor" do
|
22
|
+
require_snappy_compression
|
23
|
+
let(:compressor) { 'snappy' }
|
24
|
+
|
25
|
+
it "uses snappy" do
|
26
|
+
expect(Snappy).to receive(:deflate).with(original_message_bytes).and_call_original
|
27
|
+
message.serialize
|
28
|
+
end
|
29
|
+
end
|
16
30
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
31
|
+
context "when using the zstd compressor" do
|
32
|
+
require_zstd_compression
|
33
|
+
let(:compressor) { 'zstd' }
|
34
|
+
|
35
|
+
it "uses zstd with default compression level" do
|
36
|
+
expect(Zstd).to receive(:compress).with(original_message_bytes).and_call_original
|
37
|
+
message.serialize
|
21
38
|
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when zlib compression level is not provided' do
|
22
42
|
|
23
43
|
it 'does not set a compression level' do
|
24
44
|
expect(Zlib::Deflate).to receive(:deflate).with(original_message_bytes, nil).and_call_original
|
@@ -30,12 +50,6 @@ describe Mongo::Protocol::Compressed do
|
|
30
50
|
|
31
51
|
let(:level) { 1 }
|
32
52
|
|
33
|
-
let(:original_message_bytes) do
|
34
|
-
buf = BSON::ByteBuffer.new
|
35
|
-
original_message.send(:serialize_fields, buf)
|
36
|
-
buf.to_s
|
37
|
-
end
|
38
|
-
|
39
53
|
it 'uses the compression level' do
|
40
54
|
expect(Zlib::Deflate).to receive(:deflate).with(original_message_bytes, 1).and_call_original
|
41
55
|
message.serialize
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "spec_helper"
|
5
|
+
|
6
|
+
describe Mongo::QueryCache::Middleware do
|
7
|
+
|
8
|
+
let :middleware do
|
9
|
+
described_class.new(app)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when not touching query cache in the app" do
|
13
|
+
|
14
|
+
let(:app) do
|
15
|
+
lambda do |env|
|
16
|
+
@enabled = Mongo::QueryCache.enabled?
|
17
|
+
[200, env, "app"]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns success" do
|
22
|
+
code, _ = middleware.call({})
|
23
|
+
expect(code).to eq(200)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "enables the query cache" do
|
27
|
+
middleware.call({})
|
28
|
+
expect(@enabled).to be true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when querying in the app" do
|
33
|
+
|
34
|
+
before do
|
35
|
+
authorized_client['test'].insert_one(test: 1)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:app) do
|
39
|
+
lambda do |env|
|
40
|
+
authorized_client['test'].find
|
41
|
+
[200, env, "app"]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns success" do
|
46
|
+
code, _ = middleware.call({})
|
47
|
+
expect(code).to eq(200)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "cleans the query cache after it responds" do
|
51
|
+
middleware.call({})
|
52
|
+
expect(Mongo::QueryCache.send(:cache_table)).to be_empty
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -574,8 +574,9 @@ describe Mongo::Retryable do
|
|
574
574
|
context 'when an error due to using an unsupported storage engine occurs' do
|
575
575
|
before do
|
576
576
|
expect(operation).to receive(:execute).and_raise(
|
577
|
-
Mongo::Error::OperationFailure.new('
|
578
|
-
nil, :
|
577
|
+
Mongo::Error::OperationFailure.new('message which is not checked',
|
578
|
+
nil, code: 20, server_message: 'Transaction numbers are only allowed on...',
|
579
|
+
)).ordered
|
579
580
|
end
|
580
581
|
|
581
582
|
it 'raises an exception with the correct error message' do
|
@@ -53,6 +53,8 @@ describe Mongo::Server::AppMetadata do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
context 'when the client document exceeds the max of 512 bytes' do
|
56
|
+
# Server api parameters change metadata length
|
57
|
+
require_no_required_api_version
|
56
58
|
|
57
59
|
context 'when the os.type length is too long' do
|
58
60
|
|
@@ -589,6 +589,8 @@ describe Mongo::Server::Connection do
|
|
589
589
|
|
590
590
|
let(:server) { monitored_server }
|
591
591
|
|
592
|
+
let(:context) { Mongo::Operation::Context.new }
|
593
|
+
|
592
594
|
let!(:connection) do
|
593
595
|
described_class.new(
|
594
596
|
server,
|
@@ -620,12 +622,12 @@ describe Mongo::Server::Connection do
|
|
620
622
|
context 'when providing a single message' do
|
621
623
|
|
622
624
|
let(:reply) do
|
623
|
-
connection.dispatch([ query ])
|
625
|
+
connection.dispatch([ query ], context)
|
624
626
|
end
|
625
627
|
|
626
628
|
before do
|
627
629
|
authorized_collection.delete_many
|
628
|
-
|
630
|
+
authorized_collection.insert_one(name: 'testing')
|
629
631
|
end
|
630
632
|
|
631
633
|
it 'it dispatches the message to the socket' do
|
@@ -644,7 +646,7 @@ describe Mongo::Server::Connection do
|
|
644
646
|
end
|
645
647
|
|
646
648
|
let(:reply) do
|
647
|
-
connection.dispatch([ insert, command ])
|
649
|
+
connection.dispatch([ insert, command ], context)
|
648
650
|
end
|
649
651
|
|
650
652
|
before do
|
@@ -681,22 +683,22 @@ describe Mongo::Server::Connection do
|
|
681
683
|
end
|
682
684
|
|
683
685
|
before do
|
684
|
-
connection.dispatch([ insert ])
|
686
|
+
connection.dispatch([ insert ], context)
|
685
687
|
# Fake a query for which we did not read the response. See RUBY-1117
|
686
688
|
allow(query_bob).to receive(:replyable?) { false }
|
687
|
-
connection.dispatch([ query_bob ])
|
689
|
+
connection.dispatch([ query_bob ], context)
|
688
690
|
end
|
689
691
|
|
690
692
|
it 'raises an UnexpectedResponse error' do
|
691
693
|
expect {
|
692
|
-
connection.dispatch([ query_alice ])
|
694
|
+
connection.dispatch([ query_alice ], context)
|
693
695
|
}.to raise_error(Mongo::Error::UnexpectedResponse,
|
694
696
|
/Got response for request ID \d+ but expected response for request ID \d+/)
|
695
697
|
end
|
696
698
|
|
697
699
|
it 'marks connection perished' do
|
698
700
|
expect {
|
699
|
-
connection.dispatch([ query_alice ])
|
701
|
+
connection.dispatch([ query_alice ], context)
|
700
702
|
}.to raise_error(Mongo::Error::UnexpectedResponse)
|
701
703
|
|
702
704
|
connection.should be_error
|
@@ -704,16 +706,17 @@ describe Mongo::Server::Connection do
|
|
704
706
|
|
705
707
|
it 'makes the connection no longer usable' do
|
706
708
|
expect {
|
707
|
-
connection.dispatch([ query_alice ])
|
709
|
+
connection.dispatch([ query_alice ], context)
|
708
710
|
}.to raise_error(Mongo::Error::UnexpectedResponse)
|
709
711
|
|
710
712
|
expect {
|
711
|
-
connection.dispatch([ query_alice ])
|
713
|
+
connection.dispatch([ query_alice ], context)
|
712
714
|
}.to raise_error(Mongo::Error::ConnectionPerished)
|
713
715
|
end
|
714
716
|
end
|
715
717
|
|
716
718
|
context 'when a request is interrupted (Thread.kill)' do
|
719
|
+
require_no_required_api_version
|
717
720
|
|
718
721
|
let(:documents) do
|
719
722
|
[{ 'name' => 'bob' }, { 'name' => 'alice' }]
|
@@ -733,18 +736,19 @@ describe Mongo::Server::Connection do
|
|
733
736
|
|
734
737
|
before do
|
735
738
|
authorized_collection.delete_many
|
736
|
-
connection.dispatch([ insert ])
|
739
|
+
connection.dispatch([ insert ], context)
|
737
740
|
end
|
738
741
|
|
739
742
|
it 'closes the socket and does not use it for subsequent requests' do
|
740
743
|
t = Thread.new {
|
741
744
|
# Kill the thread just before the reply is read
|
742
745
|
allow(Mongo::Protocol::Reply).to receive(:deserialize_header) { t.kill && !t.alive? }
|
743
|
-
connection.dispatch([ query_bob ])
|
746
|
+
connection.dispatch([ query_bob ], context)
|
744
747
|
}
|
745
748
|
t.join
|
746
749
|
allow(Mongo::Protocol::Message).to receive(:deserialize_header).and_call_original
|
747
|
-
|
750
|
+
resp = connection.dispatch([ query_alice ], context)
|
751
|
+
expect(resp.documents.first['name']).to eq('alice')
|
748
752
|
end
|
749
753
|
end
|
750
754
|
|
@@ -761,7 +765,7 @@ describe Mongo::Server::Connection do
|
|
761
765
|
end
|
762
766
|
|
763
767
|
let(:reply) do
|
764
|
-
connection.dispatch([ insert ])
|
768
|
+
connection.dispatch([ insert ], context)
|
765
769
|
end
|
766
770
|
|
767
771
|
it 'checks the size against the max message size' do
|
@@ -788,7 +792,7 @@ describe Mongo::Server::Connection do
|
|
788
792
|
end
|
789
793
|
|
790
794
|
let(:reply) do
|
791
|
-
connection.dispatch([ command ])
|
795
|
+
connection.dispatch([ command ], context)
|
792
796
|
end
|
793
797
|
|
794
798
|
it 'checks the size against the max bson size' do
|
@@ -828,7 +832,7 @@ describe Mongo::Server::Connection do
|
|
828
832
|
|
829
833
|
let(:result) do
|
830
834
|
expect do
|
831
|
-
connection.dispatch([ insert ])
|
835
|
+
connection.dispatch([ insert ], context)
|
832
836
|
end.to raise_error(Mongo::Error::SocketError)
|
833
837
|
end
|
834
838
|
|
@@ -862,7 +866,7 @@ describe Mongo::Server::Connection do
|
|
862
866
|
|
863
867
|
let(:result) do
|
864
868
|
expect do
|
865
|
-
connection.dispatch([ insert ])
|
869
|
+
connection.dispatch([ insert ], context)
|
866
870
|
end.to raise_error(Mongo::Error::SocketTimeoutError)
|
867
871
|
end
|
868
872
|
|
@@ -906,6 +910,7 @@ describe Mongo::Server::Connection do
|
|
906
910
|
end
|
907
911
|
|
908
912
|
before do
|
913
|
+
authorized_collection.insert_one(test: 1)
|
909
914
|
client.cluster.next_primary
|
910
915
|
end
|
911
916
|
|
@@ -919,6 +924,8 @@ describe Mongo::Server::Connection do
|
|
919
924
|
end_time = Time.now
|
920
925
|
expect(ex).to be_a(Mongo::Error::SocketTimeoutError)
|
921
926
|
expect(ex.message).to match(/Took more than 1.5 seconds to receive data/)
|
927
|
+
else
|
928
|
+
fail 'Expected a timeout'
|
922
929
|
end
|
923
930
|
# allow 1.5 seconds +- 0.5 seconds
|
924
931
|
expect(end_time - start).to be_within(1).of(2)
|
@@ -938,7 +945,7 @@ describe Mongo::Server::Connection do
|
|
938
945
|
|
939
946
|
before do
|
940
947
|
expect(message).to receive(:replyable?) { false }
|
941
|
-
connection.send(:deliver, message,
|
948
|
+
connection.send(:deliver, message, context)
|
942
949
|
|
943
950
|
connection.send(:socket).instance_variable_set(:@timeout, -(Time.now.to_i))
|
944
951
|
end
|
@@ -9,13 +9,21 @@ describe Mongo::Server::Monitor::Connection do
|
|
9
9
|
|
10
10
|
declare_topology_double
|
11
11
|
|
12
|
+
let(:monitor_app_metadata) do
|
13
|
+
Mongo::Server::Monitor::AppMetadata.new(
|
14
|
+
server_api: SpecConfig.instance.ruby_options[:server_api],
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
12
18
|
let(:cluster) do
|
13
|
-
double('cluster').tap do |
|
14
|
-
allow(
|
15
|
-
allow(
|
16
|
-
allow(
|
17
|
-
allow(
|
18
|
-
allow(
|
19
|
+
double('cluster').tap do |cluster|
|
20
|
+
allow(cluster).to receive(:topology).and_return(topology)
|
21
|
+
allow(cluster).to receive(:app_metadata).and_return(Mongo::Server::Monitor::AppMetadata.new({}))
|
22
|
+
allow(cluster).to receive(:options).and_return({})
|
23
|
+
allow(cluster).to receive(:monitor_app_metadata).and_return(monitor_app_metadata)
|
24
|
+
allow(cluster).to receive(:push_monitor_app_metadata).and_return(monitor_app_metadata)
|
25
|
+
allow(cluster).to receive(:heartbeat_interval).and_return(1000)
|
26
|
+
allow(cluster).to receive(:run_sdam_flow)
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
@@ -27,10 +35,12 @@ describe Mongo::Server::Monitor::Connection do
|
|
27
35
|
end
|
28
36
|
|
29
37
|
let(:monitor) do
|
38
|
+
metadata = Mongo::Server::Monitor::AppMetadata.new(options)
|
30
39
|
register_background_thread_object(
|
31
40
|
Mongo::Server::Monitor.new(server, server.event_listeners, server.monitoring,
|
32
41
|
{
|
33
|
-
app_metadata:
|
42
|
+
app_metadata: metadata,
|
43
|
+
push_monitor_app_metadata: metadata,
|
34
44
|
}.update(options))
|
35
45
|
).tap do |monitor|
|
36
46
|
monitor.scan!
|