Skip to content

Commit 735daf6

Browse files
Sync CSOT spec tests (#2872)
Co-authored-by: Jamis Buck <[email protected]>
1 parent aceef6e commit 735daf6

17 files changed

+11842
-88
lines changed

lib/mongo/database/view.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def collection_names(options = {})
123123
#
124124
# @since 2.0.5
125125
def list_collections(options = {})
126-
session = client.send(:get_session, options)
126+
session = client.get_session(options)
127127
collections_info(session, ServerSelector.primary, options)
128128
end
129129

lib/mongo/index/view.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class View
100100
# @since 2.0.0
101101
def drop_one(name, options = {})
102102
raise Error::MultiIndexDrop.new if name == Index::ALL
103-
drop_by_name(name, comment: options[:comment])
103+
drop_by_name(name, options)
104104
end
105105

106106
# Drop all indexes on the collection.
@@ -117,7 +117,7 @@ def drop_one(name, options = {})
117117
#
118118
# @since 2.0.0
119119
def drop_all(options = {})
120-
drop_by_name(Index::ALL, comment: options[:comment])
120+
drop_by_name(Index::ALL, options)
121121
end
122122

123123
# Creates an index on the collection.
@@ -171,7 +171,7 @@ def create_one(keys, options = {})
171171
if session = @options[:session]
172172
create_options[:session] = session
173173
end
174-
%i(commit_quorum session comment).each do |key|
174+
%i(commit_quorum session comment timeout_ms max_time_ms).each do |key|
175175
if value = options.delete(key)
176176
create_options[key] = value
177177
end
@@ -220,7 +220,7 @@ def create_many(*models)
220220
options = models.pop
221221
end
222222

223-
client.send(:with_session, @options.merge(options)) do |session|
223+
client.with_session(@options.merge(options)) do |session|
224224
server = next_primary(nil, session)
225225

226226
indexes = normalize_models(models, server)
@@ -239,8 +239,12 @@ def create_many(*models)
239239
write_concern: write_concern,
240240
comment: options[:comment],
241241
}
242-
243-
Operation::CreateIndex.new(spec).execute(server, context: Operation::Context.new(client: client, session: session))
242+
context = Operation::Context.new(
243+
client: client,
244+
session: session,
245+
operation_timeouts: operation_timeouts(options)
246+
)
247+
Operation::CreateIndex.new(spec).execute(server, context: context)
244248
end
245249
end
246250

@@ -343,7 +347,7 @@ def operation_timeouts(opts = {})
343347

344348
private
345349

346-
def drop_by_name(name, comment: nil)
350+
def drop_by_name(name, opts = {})
347351
client.send(:with_session, @options) do |session|
348352
spec = {
349353
db_name: database.name,
@@ -352,9 +356,14 @@ def drop_by_name(name, comment: nil)
352356
session: session,
353357
write_concern: write_concern,
354358
}
355-
spec[:comment] = comment unless comment.nil?
359+
spec[:comment] = opts[:comment] unless opts[:comment].nil?
356360
server = next_primary(nil, session)
357-
Operation::DropIndex.new(spec).execute(server, context: Operation::Context.new(client: client, session: session))
361+
context = Operation::Context.new(
362+
client: client,
363+
session: session,
364+
operation_timeouts: operation_timeouts(opts)
365+
)
366+
Operation::DropIndex.new(spec).execute(server, context: context)
358367
end
359368
end
360369

lib/mongo/operation/shared/sessions_supported.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def apply_read_pref!(selector)
114114
end
115115

116116
def apply_txn_opts!(selector)
117-
session.add_txn_opts!(selector, read_command?(selector))
117+
session.add_txn_opts!(selector, read_command?(selector), context)
118118
end
119119

120120
def suppress_read_write_concern!(selector)

lib/mongo/session.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def add_txn_num!(command)
936936
#
937937
# @since 2.6.0
938938
# @api private
939-
def add_txn_opts!(command, read)
939+
def add_txn_opts!(command, read, context)
940940
command.tap do |c|
941941
# The read concern should be added to any command that starts a transaction.
942942
if starting_transaction?
@@ -990,6 +990,14 @@ def add_txn_opts!(command, read)
990990
if c[:writeConcern] && c[:writeConcern][:w] && c[:writeConcern][:w].is_a?(Symbol)
991991
c[:writeConcern][:w] = c[:writeConcern][:w].to_s
992992
end
993+
994+
# Ignore wtimeout if csot
995+
if context&.csot?
996+
c[:writeConcern]&.delete(:wtimeout)
997+
end
998+
999+
# We must not send an empty (server default) write concern.
1000+
c.delete(:writeConcern) if c[:writeConcern]&.empty?
9931001
end
9941002
end
9951003

spec/lite_spec_helper.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,6 @@ def require_atlas
168168
end
169169
end
170170

171-
if SpecConfig.instance.ci? && !%w(1 true yes).include?(ENV['INTERACTIVE']&.downcase)
172-
# Tests should take under 10 seconds ideally but it seems
173-
# we have some that run for more than 10 seconds in CI.
174-
config.around(:each) do |example|
175-
TimeoutInterrupt.timeout(example_timeout_seconds, ExampleTimeout) do
176-
example.run
177-
end
178-
end
179-
end
180-
181171
if SpecConfig.instance.ci?
182172
if defined?(Rfc::Rif)
183173
unless BSON::Environment.jruby?

spec/runners/unified/crud_operations.rb

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def get_find_view(op)
2323
'allowDiskUse', 'returnKey', 'projection',
2424
'skip', 'hint', 'maxTimeMS', 'timeoutMS',
2525
'collation', 'noCursorTimeout', 'oplogReplay', 'allowPartialResults',
26-
'timeoutMode',
26+
'timeoutMode', 'maxAwaitTimeMS', 'cursorType', 'timeoutMode',
2727
{ 'showRecordId' => :show_disk_loc, 'max' => :max_value, 'min' => :min_value },
2828
allow_extra: true)
29-
symbolize_options!(opts, :timeout_mode)
29+
symbolize_options!(opts, :timeout_mode, :cursor_type)
3030

3131
opts[:session] = entities.get(:session, session) if session
3232

@@ -50,49 +50,31 @@ def get_find_view(op)
5050
def count(op)
5151
collection = entities.get(:collection, op.use!('object'))
5252
use_arguments(op) do |args|
53-
opts = {}
53+
opts = extract_options(args, 'comment', 'timeoutMS', 'maxTimeMS', allow_extra: true)
5454
if session = args.use('session')
5555
opts[:session] = entities.get(:session, session)
5656
end
57-
if comment = args.use('comment')
58-
opts[:comment] = comment
59-
end
60-
if timeout_ms = args.use('timeoutMS')
61-
opts[:timeout_ms] = timeout_ms
62-
end
6357
collection.count(args.use!('filter'), **opts)
6458
end
6559
end
6660

6761
def count_documents(op)
6862
collection = entities.get(:collection, op.use!('object'))
6963
use_arguments(op) do |args|
70-
opts = {}
64+
opts = extract_options(args, 'comment', 'timeoutMS', 'maxTimeMS', allow_extra: true)
7165
if session = args.use('session')
7266
opts[:session] = entities.get(:session, session)
7367
end
74-
if comment = args.use('comment')
75-
opts[:comment] = comment
76-
end
77-
if timeout_ms = args.use('timeoutMS')
78-
opts[:timeout_ms] = timeout_ms
79-
end
8068
collection.find(args.use!('filter')).count_documents(**opts)
8169
end
8270
end
8371

8472
def estimated_document_count(op)
8573
collection = entities.get(:collection, op.use!('object'))
8674
use_arguments(op) do |args|
87-
opts = {}
88-
if max_time_ms = args.use('maxTimeMS')
89-
opts[:max_time_ms] = max_time_ms
90-
end
91-
if comment = args.use('comment')
92-
opts[:comment] = comment
93-
end
94-
if timeout_ms = args.use('timeoutMS')
95-
opts[:timeout_ms] = timeout_ms
75+
opts = extract_options(args, 'comment', 'timeoutMS', 'maxTimeMS', allow_extra: true)
76+
if session = args.use('session')
77+
opts[:session] = entities.get(:session, session)
9678
end
9779
collection.estimated_document_count(**opts)
9880
end
@@ -101,16 +83,10 @@ def estimated_document_count(op)
10183
def distinct(op)
10284
collection = entities.get(:collection, op.use!('object'))
10385
use_arguments(op) do |args|
104-
opts = {}
86+
opts = extract_options(args, 'comment', 'timeoutMS', 'maxTimeMS', allow_extra: true)
10587
if session = args.use('session')
10688
opts[:session] = entities.get(:session, session)
10789
end
108-
if comment = args.use('comment')
109-
opts[:comment] = comment
110-
end
111-
if timeout_ms = args.use('timeoutMS')
112-
opts[:timeout_ms] = timeout_ms
113-
end
11490
req = collection.find(args.use!('filter'), **opts).distinct(args.use!('fieldName'), **opts)
11591
result = req.to_a
11692
end
@@ -126,16 +102,15 @@ def find_one_and_update(op)
126102
comment: args.use('comment'),
127103
hint: args.use('hint'),
128104
upsert: args.use('upsert'),
105+
timeout_ms: args.use('timeoutMS'),
106+
max_time_ms: args.use('maxTimeMS')
129107
}
130108
if return_document = args.use('returnDocument')
131109
opts[:return_document] = return_document.downcase.to_sym
132110
end
133111
if session = args.use('session')
134112
opts[:session] = entities.get(:session, session)
135113
end
136-
if timeout_ms = args.use('timeoutMS')
137-
opts[:timeout_ms] = timeout_ms
138-
end
139114
collection.find_one_and_update(filter, update, **opts)
140115
end
141116
end
@@ -149,13 +124,12 @@ def find_one_and_replace(op)
149124
let: args.use('let'),
150125
comment: args.use('comment'),
151126
hint: args.use('hint'),
127+
timeout_ms: args.use('timeoutMS'),
128+
max_time_ms: args.use('maxTimeMS')
152129
}
153130
if session = args.use('session')
154131
opts[:session] = entities.get(:session, session)
155132
end
156-
if timeout_ms = args.use('timeoutMS')
157-
opts[:timeout_ms] = timeout_ms
158-
end
159133
collection.find_one_and_replace(filter, update, **opts)
160134
end
161135
end
@@ -168,13 +142,12 @@ def find_one_and_delete(op)
168142
let: args.use('let'),
169143
comment: args.use('comment'),
170144
hint: args.use('hint'),
145+
timeout_ms: args.use('timeoutMS'),
146+
max_time_ms: args.use('maxTimeMS')
171147
}
172148
if session = args.use('session')
173149
opts[:session] = entities.get(:session, session)
174150
end
175-
if timeout_ms = args.use('timeoutMS')
176-
opts[:timeout_ms] = timeout_ms
177-
end
178151
collection.find_one_and_delete(filter, **opts)
179152
end
180153
end
@@ -184,7 +157,8 @@ def insert_one(op)
184157
use_arguments(op) do |args|
185158
opts = {
186159
comment: args.use('comment'),
187-
timeout_ms: args.use('timeoutMS')
160+
timeout_ms: args.use('timeoutMS'),
161+
max_time_ms: args.use('maxTimeMS')
188162
}
189163
if session = args.use('session')
190164
opts[:session] = entities.get(:session, session)
@@ -197,17 +171,16 @@ def insert_many(op)
197171
collection = entities.get(:collection, op.use!('object'))
198172
use_arguments(op) do |args|
199173
opts = {
200-
comment: args.use('comment')
174+
comment: args.use('comment'),
175+
timeout_ms: args.use('timeoutMS'),
176+
max_time_ms: args.use('maxTimeMS')
201177
}
202178
unless (ordered = args.use('ordered')).nil?
203179
opts[:ordered] = ordered
204180
end
205181
if session = args.use('session')
206182
opts[:session] = entities.get(:session, session)
207183
end
208-
if timeout_ms = args.use('timeoutMS')
209-
opts[:timeout_ms] = timeout_ms
210-
end
211184
collection.insert_many(args.use!('documents'), **opts)
212185
end
213186
end
@@ -221,6 +194,7 @@ def update_one(op)
221194
hint: args.use('hint'),
222195
upsert: args.use('upsert'),
223196
timeout_ms: args.use('timeoutMS'),
197+
max_time_ms: args.use('maxTimeMS')
224198
}
225199
if session = args.use('session')
226200
opts[:session] = entities.get(:session, session)
@@ -237,6 +211,7 @@ def update_many(op)
237211
comment: args.use('comment'),
238212
hint: args.use('hint'),
239213
timeout_ms: args.use('timeoutMS'),
214+
max_time_ms: args.use('maxTimeMS')
240215
}
241216
collection.update_many(args.use!('filter'), args.use!('update'), **opts)
242217
end
@@ -252,7 +227,8 @@ def replace_one(op)
252227
upsert: args.use('upsert'),
253228
let: args.use('let'),
254229
hint: args.use('hint'),
255-
timeout_ms: args.use('timeoutMS')
230+
timeout_ms: args.use('timeoutMS'),
231+
max_time_ms: args.use('maxTimeMS')
256232
)
257233
end
258234
end
@@ -264,13 +240,12 @@ def delete_one(op)
264240
let: args.use('let'),
265241
comment: args.use('comment'),
266242
hint: args.use('hint'),
243+
timeout_ms: args.use('timeoutMS'),
244+
max_time_ms: args.use('maxTimeMS')
267245
}
268246
if session = args.use('session')
269247
opts[:session] = entities.get(:session, session)
270248
end
271-
if timeout_ms = args.use('timeoutMS')
272-
opts[:timeout_ms] = timeout_ms
273-
end
274249
collection.delete_one(args.use!('filter'), **opts)
275250
end
276251
end
@@ -282,6 +257,8 @@ def delete_many(op)
282257
let: args.use('let'),
283258
comment: args.use('comment'),
284259
hint: args.use('hint'),
260+
timeout_ms: args.use('timeoutMS'),
261+
max_time_ms: args.use('maxTimeMS')
285262
}
286263
collection.delete_many(args.use!('filter'), **opts)
287264
end
@@ -306,6 +283,9 @@ def bulk_write(op)
306283
if timeout_ms = args.use('timeoutMS')
307284
opts[:timeout_ms] = timeout_ms
308285
end
286+
if max_time_ms = args.use('maxTimeMS')
287+
opts[:max_time_ms] = max_time_ms
288+
end
309289
collection.bulk_write(requests, **opts)
310290
end
311291
end
@@ -315,18 +295,14 @@ def aggregate(op)
315295
args = op.use!('arguments')
316296
pipeline = args.use!('pipeline')
317297

318-
opts = extract_options(args, 'let', 'comment', 'batchSize',
319-
'allowDiskUse', 'timeoutMode', 'timeoutMS', allow_extra: true)
298+
opts = extract_options(args, 'let', 'comment', 'batchSize', 'maxTimeMS',
299+
'allowDiskUse', 'timeoutMode', 'timeoutMS', 'maxTimeMS', allow_extra: true)
320300
symbolize_options!(opts, :timeout_mode)
321301

322302
if session = args.use('session')
323303
opts[:session] = entities.get(:session, session)
324304
end
325305

326-
if timeout_ms = args.use('timeoutMS')
327-
opts[:timeout_ms] = timeout_ms
328-
end
329-
330306
unless args.empty?
331307
raise NotImplementedError, "Unhandled spec keys: #{args} in #{test_spec}"
332308
end
@@ -339,7 +315,8 @@ def create_find_cursor(op)
339315
args = op.use!('arguments')
340316

341317
filter = args.use('filter')
342-
opts = extract_options(args, 'batchSize', 'timeoutMS')
318+
opts = extract_options(args, 'batchSize', 'timeoutMS', 'cursorType', 'maxAwaitTimeMS')
319+
symbolize_options!(opts, :cursor_type)
343320

344321
view = obj.find(filter, opts)
345322
view.each # to initialize the cursor

0 commit comments

Comments
 (0)