mongo 2.14.0.rc1 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -1
- data/Rakefile +39 -4
- data/lib/mongo/address.rb +1 -1
- data/lib/mongo/collection.rb +5 -0
- data/lib/mongo/collection/view/readable.rb +4 -0
- data/lib/mongo/cursor.rb +15 -3
- data/lib/mongo/database/view.rb +1 -1
- data/lib/mongo/operation/collections_info/command.rb +5 -0
- data/lib/mongo/operation/collections_info/result.rb +16 -1
- data/lib/mongo/operation/find/result.rb +10 -0
- data/lib/mongo/server/description.rb +8 -1
- data/lib/mongo/session.rb +2 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/README.md +7 -0
- data/spec/integration/bson_symbol_spec.rb +4 -2
- data/spec/integration/change_stream_spec.rb +1 -1
- data/spec/integration/connection_pool_populator_spec.rb +1 -1
- data/spec/integration/cursor_reaping_spec.rb +1 -1
- data/spec/integration/fork_reconnect_spec.rb +56 -1
- data/spec/integration/query_cache_transactions_spec.rb +29 -18
- data/spec/integration/sdam_error_handling_spec.rb +17 -0
- data/spec/integration/sdam_events_spec.rb +8 -5
- data/spec/integration/transactions_examples_spec.rb +17 -7
- data/spec/lite_spec_helper.rb +5 -3
- data/spec/mongo/auth/user_spec.rb +1 -1
- data/spec/mongo/bulk_write_spec.rb +2 -2
- data/spec/mongo/client_construction_spec.rb +3 -3
- data/spec/mongo/client_encryption_spec.rb +16 -10
- data/spec/mongo/client_spec.rb +7 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +1 -1
- data/spec/mongo/cluster/topology/sharded_spec.rb +1 -1
- data/spec/mongo/cluster/topology/single_spec.rb +1 -1
- data/spec/mongo/cluster/topology/unknown_spec.rb +1 -1
- data/spec/mongo/cluster/topology_spec.rb +1 -1
- data/spec/mongo/collection/view/change_stream_resume_spec.rb +1 -1
- data/spec/mongo/collection/view/readable_spec.rb +36 -0
- data/spec/mongo/collection_spec.rb +12 -0
- data/spec/mongo/crypt/binary_spec.rb +1 -6
- data/spec/mongo/crypt/binding/binary_spec.rb +1 -6
- data/spec/mongo/crypt/binding/context_spec.rb +2 -7
- data/spec/mongo/crypt/binding/helpers_spec.rb +1 -6
- data/spec/mongo/crypt/binding/mongocrypt_spec.rb +2 -7
- data/spec/mongo/crypt/binding/status_spec.rb +1 -6
- data/spec/mongo/crypt/binding/version_spec.rb +1 -6
- data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
- data/spec/mongo/crypt/status_spec.rb +1 -6
- data/spec/mongo/database_spec.rb +64 -0
- data/spec/mongo/monitoring/event/server_closed_spec.rb +1 -1
- data/spec/mongo/monitoring/event/server_opening_spec.rb +1 -1
- data/spec/mongo/monitoring/event/topology_changed_spec.rb +1 -1
- data/spec/mongo/monitoring/event/topology_closed_spec.rb +1 -1
- data/spec/mongo/monitoring/event/topology_opening_spec.rb +1 -1
- data/spec/mongo/operation/delete/op_msg_spec.rb +3 -3
- data/spec/mongo/operation/insert/command_spec.rb +2 -2
- data/spec/mongo/operation/insert/op_msg_spec.rb +3 -3
- data/spec/mongo/operation/read_preference_op_msg_spec.rb +1 -1
- data/spec/mongo/operation/update/command_spec.rb +2 -2
- data/spec/mongo/operation/update/op_msg_spec.rb +3 -3
- data/spec/mongo/query_cache_spec.rb +1 -0
- data/spec/mongo/server/app_metadata_shared.rb +2 -2
- data/spec/mongo/server/connection_spec.rb +1 -1
- data/spec/mongo/server/description_spec.rb +18 -0
- data/spec/mongo/server_selector_spec.rb +2 -2
- data/spec/mongo/socket/ssl_spec.rb +3 -3
- data/spec/runners/change_streams/test.rb +1 -1
- data/spec/runners/crud/test_base.rb +0 -19
- data/spec/runners/server_selection.rb +1 -1
- data/spec/runners/transactions/test.rb +2 -2
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/constraints.rb +303 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/stress/fork_reconnect_stress_spec.rb +1 -1
- data/spec/support/constraints.rb +0 -270
- data/spec/support/utils.rb +19 -0
- metadata +956 -952
- metadata.gz.sig +0 -0
- data/spec/support/child_process_helper.rb +0 -78
- data/spec/support/lite_constraints.rb +0 -165
- data/spec/support/spec_organizer.rb +0 -129
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bfb22d052a842e256744a88c7e3cbd3b958643cc3e0f4425bf97be8f913f167
|
4
|
+
data.tar.gz: b63f3605ad8223e99a5f6a62aabff94a8c8600095b84265b6b4deb38e7223013
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85566c0080b9bcfa67438a365114dd062425df557040e05c0db0448aedd37a0f52dae5b8612b08af196a9e35c1e5b41553a89607d780d187d4e2e28602471c76
|
7
|
+
data.tar.gz: 5172ab2d71a8d7e048fcb2d87e7219024a2028c3909f2cce48081d1b3014071df13b02426019508bda6542e4870992ca869cd3393caf3aaf6483ad4c74f1abf3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
��0���H#{�F������ƛ!z�����}��6l��kM��h.[��hAi�<y/&BM~|2��֘�s�s����o@�]k�d�w�xǴp+��ȿ�
|
data/Rakefile
CHANGED
@@ -13,7 +13,31 @@ end
|
|
13
13
|
default_groups = [:default, :testing]
|
14
14
|
Bundler.require(*default_groups)
|
15
15
|
|
16
|
+
ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
|
17
|
+
|
18
|
+
$: << File.join(ROOT, 'spec/shared/lib')
|
19
|
+
|
16
20
|
require 'rspec/core/rake_task'
|
21
|
+
require 'mrss/spec_organizer'
|
22
|
+
|
23
|
+
CLASSIFIERS = [
|
24
|
+
[%r,^mongo,, :unit],
|
25
|
+
[%r,^kerberos,, :unit],
|
26
|
+
[%r,^integration/sdam_error_handling,, :sdam_integration],
|
27
|
+
[%r,^integration/cursor_reaping,, :cursor_reaping],
|
28
|
+
[%r,^integration/query_cache,, :query_cache],
|
29
|
+
[%r,^integration/transactions_examples,, :tx_examples],
|
30
|
+
[%r,^(atlas|integration),, :integration],
|
31
|
+
[%r,^spec_tests/sdam_integration,, :spec_sdam_integration],
|
32
|
+
[%r,^spec_tests,, :spec],
|
33
|
+
]
|
34
|
+
|
35
|
+
RUN_PRIORITY = %i(
|
36
|
+
tx_examples
|
37
|
+
unit
|
38
|
+
integration sdam_integration cursor_reaping query_cache
|
39
|
+
spec spec_sdam_integration
|
40
|
+
)
|
17
41
|
|
18
42
|
tasks = Rake.application.instance_variable_get('@tasks')
|
19
43
|
tasks['release:do'] = tasks.delete('release')
|
@@ -71,12 +95,23 @@ namespace :spec do
|
|
71
95
|
SpecConfig.instance.print_summary
|
72
96
|
end
|
73
97
|
|
74
|
-
|
75
|
-
|
98
|
+
def spec_organizer
|
99
|
+
Mrss::SpecOrganizer.new(
|
100
|
+
root: ROOT,
|
101
|
+
classifiers: CLASSIFIERS,
|
102
|
+
priority_order: RUN_PRIORITY,
|
103
|
+
)
|
104
|
+
end
|
76
105
|
|
77
|
-
|
106
|
+
task :ci => ['spec:prepare'] do
|
107
|
+
spec_organizer.run
|
108
|
+
end
|
78
109
|
|
79
|
-
|
110
|
+
desc 'Show test buckets'
|
111
|
+
task :buckets do
|
112
|
+
spec_organizer.ordered_buckets.each do |category, paths|
|
113
|
+
puts "#{category || 'remaining'}: #{paths&.join(' ') || '<none>'}"
|
114
|
+
end
|
80
115
|
end
|
81
116
|
end
|
82
117
|
|
data/lib/mongo/address.rb
CHANGED
@@ -286,7 +286,7 @@ module Mongo
|
|
286
286
|
rescue IOError, SystemCallError => e
|
287
287
|
raise Error::SocketError, "#{e.class}: #{e} (for #{self})"
|
288
288
|
rescue OpenSSL::SSL::SSLError => e
|
289
|
-
raise Error::SocketError, "#{e.class}: #{e} (for #{self})
|
289
|
+
raise Error::SocketError, "#{e.class}: #{e} (for #{self})"
|
290
290
|
end
|
291
291
|
end
|
292
292
|
end
|
data/lib/mongo/collection.rb
CHANGED
@@ -564,6 +564,11 @@ module Mongo
|
|
564
564
|
else
|
565
565
|
write_concern_with_session(session)
|
566
566
|
end
|
567
|
+
|
568
|
+
if document.nil?
|
569
|
+
raise ArgumentError, "Document to be inserted cannot be nil"
|
570
|
+
end
|
571
|
+
|
567
572
|
write_with_retry(session, write_concern) do |server, txn_num|
|
568
573
|
Operation::Insert.new(
|
569
574
|
:documents => [ document ],
|
@@ -226,6 +226,10 @@ module Mongo
|
|
226
226
|
#
|
227
227
|
# @since 2.6.0
|
228
228
|
def estimated_document_count(opts = {})
|
229
|
+
unless view.filter.empty?
|
230
|
+
raise ArgumentError, "Cannot call estimated_document_count when querying with a filter"
|
231
|
+
end
|
232
|
+
|
229
233
|
cmd = { count: collection.name }
|
230
234
|
cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
|
231
235
|
if read_concern
|
data/lib/mongo/cursor.rb
CHANGED
@@ -69,12 +69,12 @@ module Mongo
|
|
69
69
|
@view = view
|
70
70
|
@server = server
|
71
71
|
@initial_result = result
|
72
|
+
@namespace = result.namespace
|
72
73
|
@remaining = limit if limited?
|
73
74
|
@cursor_id = result.cursor_id
|
74
75
|
if @cursor_id.nil?
|
75
76
|
raise ArgumentError, 'Cursor id must be present in the result'
|
76
77
|
end
|
77
|
-
@coll_name = nil
|
78
78
|
@options = options
|
79
79
|
@session = @options[:session]
|
80
80
|
unless closed?
|
@@ -288,7 +288,20 @@ module Mongo
|
|
288
288
|
#
|
289
289
|
# @since 2.2.0
|
290
290
|
def collection_name
|
291
|
-
|
291
|
+
# In most cases, this will be equivalent to the name of the collection
|
292
|
+
# object in the driver. However, in some cases (e.g. when connected
|
293
|
+
# to an Atlas Data Lake), the namespace returned by the find command
|
294
|
+
# may be different, which is why we want to use the collection name based
|
295
|
+
# on the namespace in the command result.
|
296
|
+
if @namespace
|
297
|
+
# Often, the namespace will be in the format "database.collection".
|
298
|
+
# However, sometimes the collection name will contain periods, which
|
299
|
+
# is why this method joins all the namespace components after the first.
|
300
|
+
ns_components = @namespace.split('.')
|
301
|
+
ns_components[1...ns_components.length].join('.')
|
302
|
+
else
|
303
|
+
collection.name
|
304
|
+
end
|
292
305
|
end
|
293
306
|
|
294
307
|
# Get the cursor id.
|
@@ -382,7 +395,6 @@ module Mongo
|
|
382
395
|
|
383
396
|
def process(result)
|
384
397
|
@remaining -= result.returned_count if limited?
|
385
|
-
@coll_name ||= result.namespace.sub("#{database.name}.", '') if result.namespace
|
386
398
|
# #process is called for the first batch of results. In this case
|
387
399
|
# the @cursor_id may be zero (all results fit in the first batch).
|
388
400
|
# Thus we need to check both @cursor_id and the cursor_id of the result
|
data/lib/mongo/database/view.rb
CHANGED
@@ -100,7 +100,7 @@ module Mongo
|
|
100
100
|
#
|
101
101
|
# @return [ Array<Hash> ] Info for each collection in the database.
|
102
102
|
#
|
103
|
-
# @since 2.0.5
|
103
|
+
# @since 2.0.5
|
104
104
|
def list_collections(options = {})
|
105
105
|
session = client.send(:get_session)
|
106
106
|
collections_info(session, ServerSelector.primary, options)
|
@@ -23,6 +23,21 @@ module Mongo
|
|
23
23
|
# @api semiprivate
|
24
24
|
class Result < Operation::Result
|
25
25
|
|
26
|
+
# Initialize a new result.
|
27
|
+
#
|
28
|
+
# @param [ Array<Protocol::Message> | nil ] replies The wire protocol replies, if any.
|
29
|
+
# @param [ Server::Description ] connection_description
|
30
|
+
# Server description of the server that performed the operation that
|
31
|
+
# this result is for.
|
32
|
+
# @param [ String ] database_name The name of the database that the
|
33
|
+
# query was sent to.
|
34
|
+
#
|
35
|
+
# @api private
|
36
|
+
def initialize(replies, connection_description, database_name)
|
37
|
+
super(replies, connection_description)
|
38
|
+
@database_name = database_name
|
39
|
+
end
|
40
|
+
|
26
41
|
# Get the namespace for the cursor.
|
27
42
|
#
|
28
43
|
# @example Get the namespace.
|
@@ -33,7 +48,7 @@ module Mongo
|
|
33
48
|
# @since 2.1.0
|
34
49
|
# @api private
|
35
50
|
def namespace
|
36
|
-
Database::NAMESPACES
|
51
|
+
"#{@database_name}.#{Database::NAMESPACES}"
|
37
52
|
end
|
38
53
|
end
|
39
54
|
end
|
@@ -48,6 +48,16 @@ module Mongo
|
|
48
48
|
cursor_document[FIRST_BATCH]
|
49
49
|
end
|
50
50
|
|
51
|
+
# The namespace in which this find command was performed.
|
52
|
+
#
|
53
|
+
# @return [ String ] The namespace, usually in the format
|
54
|
+
# "database.collection".
|
55
|
+
#
|
56
|
+
# @api private
|
57
|
+
def namespace
|
58
|
+
cursor_document['ns']
|
59
|
+
end
|
60
|
+
|
51
61
|
private
|
52
62
|
|
53
63
|
def cursor_document
|
@@ -182,13 +182,20 @@ module Mongo
|
|
182
182
|
# @since 2.5.0
|
183
183
|
LOGICAL_SESSION_TIMEOUT_MINUTES = 'logicalSessionTimeoutMinutes'.freeze
|
184
184
|
|
185
|
+
# Constant for reading connectionId info from config.
|
186
|
+
#
|
187
|
+
# @api private
|
188
|
+
CONNECTION_ID = 'connectionId'.freeze
|
189
|
+
|
185
190
|
# Fields to exclude when comparing two descriptions.
|
186
191
|
#
|
187
192
|
# @since 2.0.6
|
188
193
|
EXCLUDE_FOR_COMPARISON = [ LOCAL_TIME,
|
189
194
|
LAST_WRITE,
|
190
195
|
OPERATION_TIME,
|
191
|
-
Operation::CLUSTER_TIME
|
196
|
+
Operation::CLUSTER_TIME,
|
197
|
+
CONNECTION_ID,
|
198
|
+
].freeze
|
192
199
|
|
193
200
|
# Instantiate the new server description from the result of the ismaster
|
194
201
|
# command.
|
data/lib/mongo/session.rb
CHANGED
@@ -379,6 +379,7 @@ module Mongo
|
|
379
379
|
rv = yield self
|
380
380
|
rescue Exception => e
|
381
381
|
if within_states?(STARTING_TRANSACTION_STATE, TRANSACTION_IN_PROGRESS_STATE)
|
382
|
+
log_warn("Aborting transaction due to #{e.class}: #{e}")
|
382
383
|
abort_transaction
|
383
384
|
transaction_in_progress = false
|
384
385
|
end
|
@@ -443,7 +444,7 @@ module Mongo
|
|
443
444
|
true
|
444
445
|
ensure
|
445
446
|
if transaction_in_progress
|
446
|
-
log_warn('with_transaction callback
|
447
|
+
log_warn('with_transaction callback broke out of with_transaction loop, aborting transaction')
|
447
448
|
begin
|
448
449
|
abort_transaction
|
449
450
|
rescue Error::OperationFailure, Error::InvalidTransactionOperation
|
data/lib/mongo/version.rb
CHANGED
data/spec/README.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## Quick Start
|
4
4
|
|
5
|
+
The test suite requires shared tooling that is stored in a separate repository
|
6
|
+
and is referenced as a submodule. After checking out the desired driver
|
7
|
+
branch, check out the matching submodules:
|
8
|
+
|
9
|
+
git submodule init
|
10
|
+
git submodule update
|
11
|
+
|
5
12
|
To run the test suite against a local MongoDB deployment listening on port
|
6
13
|
27017, run:
|
7
14
|
|
@@ -25,8 +25,10 @@ describe 'Symbol encoding to BSON' do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'round-trips symbol values using the same byte buffer' do
|
28
|
-
if BSON::Environment.jruby?
|
29
|
-
|
28
|
+
if BSON::Environment.jruby? && (BSON::VERSION.split('.').map(&:to_i) <=> [4, 11, 0]) < 0
|
29
|
+
skip 'This test is only relevant to bson versions that increment ByteBuffer '\
|
30
|
+
'read and write positions separately in JRuby, as implemented in ' \
|
31
|
+
'bson version 4.11.0. For more information, see https://jira.mongodb.org/browse/RUBY-2128'
|
30
32
|
end
|
31
33
|
|
32
34
|
Hash.from_bson(hash.to_bson).should == hash
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe 'Cursor reaping' do
|
4
4
|
# JRuby does reap cursors but GC.start does not force GC to run like it does
|
5
5
|
# in MRI, I don't currently know how to force GC to run in JRuby
|
6
|
-
|
6
|
+
require_mri
|
7
7
|
|
8
8
|
around(:all) do |example|
|
9
9
|
saved_level = Mongo::Logger.logger.level
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'fork reconnect' do
|
4
4
|
require_fork
|
5
|
-
|
5
|
+
require_mri
|
6
6
|
|
7
7
|
# On multi-shard sharded clusters a succeeding write request does not
|
8
8
|
# guarantee that the next operation will succeed (since it could be sent to
|
@@ -139,5 +139,60 @@ describe 'fork reconnect' do
|
|
139
139
|
# performed by the child is recovered from.
|
140
140
|
client['foo'].find(test: 1)
|
141
141
|
end
|
142
|
+
|
143
|
+
# Test from Driver Sessions Spec
|
144
|
+
# * Create ClientSession
|
145
|
+
# * Record its lsid
|
146
|
+
# * Delete it (so the lsid is pushed into the pool)
|
147
|
+
# * Fork
|
148
|
+
# * In the parent, create a ClientSession and assert its lsid is the same.
|
149
|
+
# * In the child, create a ClientSession and assert its lsid is different.
|
150
|
+
describe 'session pool' do
|
151
|
+
it 'is cleared after fork' do
|
152
|
+
session = client.get_session
|
153
|
+
parent_lsid = session.session_id
|
154
|
+
session.end_session
|
155
|
+
if pid = fork
|
156
|
+
pid, status = Process.wait2(pid)
|
157
|
+
status.exitstatus.should == 0
|
158
|
+
else
|
159
|
+
Utils.wrap_forked_child do
|
160
|
+
client.reconnect
|
161
|
+
child_session = client.get_session
|
162
|
+
child_lsid = child_session.session_id
|
163
|
+
expect(child_lsid).not_to eq(parent_lsid)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
expect(client.get_session.session_id).to eq(parent_lsid)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Test from Driver Sessions Spec
|
171
|
+
# * Create ClientSession
|
172
|
+
# * Record its lsid
|
173
|
+
# * Fork
|
174
|
+
# * In the parent, return the ClientSession to the pool, create a new ClientSession, and assert its lsid is the same.
|
175
|
+
# * In the child, return the ClientSession to the pool, create a new ClientSession, and assert its lsid is different.
|
176
|
+
it 'does not return parent process sessions to child process pool' do
|
177
|
+
session = client.get_session
|
178
|
+
parent_lsid = session.session_id
|
179
|
+
|
180
|
+
if pid = fork
|
181
|
+
pid, status = Process.wait2(pid)
|
182
|
+
status.exitstatus.should == 0
|
183
|
+
else
|
184
|
+
Utils.wrap_forked_child do
|
185
|
+
client.reconnect
|
186
|
+
session.end_session
|
187
|
+
child_session = client.get_session
|
188
|
+
child_lsid = child_session.session_id
|
189
|
+
expect(child_lsid).not_to eq(parent_lsid)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
session.end_session
|
194
|
+
expect(client.get_session.session_id).to eq(parent_lsid)
|
195
|
+
end
|
196
|
+
end
|
142
197
|
end
|
143
198
|
end
|
@@ -1,16 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'QueryCache with transactions' do
|
4
|
+
# Work around https://jira.mongodb.org/browse/HELP-10518
|
5
|
+
before(:all) do
|
6
|
+
client = ClientRegistry.instance.global_client('authorized')
|
7
|
+
Utils.create_collection(client, 'test')
|
8
|
+
|
9
|
+
Utils.mongos_each_direct_client do |client|
|
10
|
+
client['test'].distinct('foo').to_a
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
around do |spec|
|
5
15
|
Mongo::QueryCache.clear
|
6
16
|
Mongo::QueryCache.cache { spec.run }
|
7
17
|
end
|
8
18
|
|
9
|
-
before do
|
10
|
-
authorized_collection.delete_many
|
11
|
-
subscriber.clear_events!
|
12
|
-
end
|
13
|
-
|
14
19
|
# These tests do not currently use the session registry because transactions
|
15
20
|
# leak sessions independently of the query cache. This will be resolved by
|
16
21
|
# RUBY-2391.
|
@@ -23,28 +28,34 @@ describe 'QueryCache with transactions' do
|
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
|
-
|
31
|
+
before do
|
32
|
+
collection.delete_many
|
33
|
+
|
34
|
+
# Work around https://jira.mongodb.org/browse/HELP-10518
|
35
|
+
client.start_session do |session|
|
36
|
+
session.with_transaction do
|
37
|
+
collection.find({}, session: session).to_a
|
38
|
+
end
|
39
|
+
end
|
40
|
+
subscriber.clear_events!
|
41
|
+
end
|
27
42
|
|
28
43
|
describe 'in transactions' do
|
29
44
|
require_transaction_support
|
30
45
|
require_wired_tiger
|
31
46
|
|
32
|
-
let(:collection) {
|
47
|
+
let(:collection) { client['test'] }
|
33
48
|
|
34
49
|
let(:events) do
|
35
50
|
subscriber.command_started_events('find')
|
36
51
|
end
|
37
52
|
|
38
|
-
before do
|
39
|
-
Utils.create_collection(authorized_client, 'test')
|
40
|
-
end
|
41
|
-
|
42
53
|
context 'with convenient API' do
|
43
54
|
context 'when same query is performed inside and outside of transaction' do
|
44
55
|
it 'performs one query' do
|
45
56
|
collection.find.to_a
|
46
57
|
|
47
|
-
session =
|
58
|
+
session = client.start_session
|
48
59
|
session.with_transaction do
|
49
60
|
collection.find({}, session: session).to_a
|
50
61
|
end
|
@@ -57,7 +68,7 @@ describe 'QueryCache with transactions' do
|
|
57
68
|
it 'performs two queries' do
|
58
69
|
collection.find.to_a
|
59
70
|
|
60
|
-
session =
|
71
|
+
session = client.start_session
|
61
72
|
session.with_transaction(
|
62
73
|
read_concern: { level: :snapshot }
|
63
74
|
) do
|
@@ -72,7 +83,7 @@ describe 'QueryCache with transactions' do
|
|
72
83
|
it 'performs two queries' do
|
73
84
|
collection.find.to_a
|
74
85
|
|
75
|
-
session =
|
86
|
+
session = client.start_session
|
76
87
|
session.with_transaction(
|
77
88
|
read: { mode: :primary }
|
78
89
|
) do
|
@@ -85,7 +96,7 @@ describe 'QueryCache with transactions' do
|
|
85
96
|
|
86
97
|
context 'when transaction is committed' do
|
87
98
|
it 'clears the cache' do
|
88
|
-
session =
|
99
|
+
session = client.start_session
|
89
100
|
session.with_transaction do
|
90
101
|
collection.insert_one({ test: 1 }, session: session)
|
91
102
|
collection.insert_one({ test: 2 }, session: session)
|
@@ -107,7 +118,7 @@ describe 'QueryCache with transactions' do
|
|
107
118
|
|
108
119
|
context 'when transaction is aborted' do
|
109
120
|
it 'clears the cache' do
|
110
|
-
session =
|
121
|
+
session = client.start_session
|
111
122
|
session.with_transaction do
|
112
123
|
collection.insert_one({ test: 1 }, session: session)
|
113
124
|
collection.insert_one({ test: 2 }, session: session)
|
@@ -131,7 +142,7 @@ describe 'QueryCache with transactions' do
|
|
131
142
|
context 'with low-level API' do
|
132
143
|
context 'when transaction is committed' do
|
133
144
|
it 'clears the cache' do
|
134
|
-
session =
|
145
|
+
session = client.start_session
|
135
146
|
session.start_transaction
|
136
147
|
|
137
148
|
collection.insert_one({ test: 1 }, session: session)
|
@@ -154,7 +165,7 @@ describe 'QueryCache with transactions' do
|
|
154
165
|
|
155
166
|
context 'when transaction is aborted' do
|
156
167
|
it 'clears the cache' do
|
157
|
-
session =
|
168
|
+
session = client.start_session
|
158
169
|
session.start_transaction
|
159
170
|
|
160
171
|
collection.insert_one({ test: 1 }, session: session)
|