Skip to content

Commit 125a43b

Browse files
p-mongop
andauthored
RUBY-2484 Update unified test runner for integration with drivers-atlas-testing (#2157)
* RUBY-2484 amend driver to be usable by astrolabe workload executor * RUBY-2484 accept mongo client options override Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>
1 parent a72ce6d commit 125a43b

File tree

12 files changed

+159
-73
lines changed

12 files changed

+159
-73
lines changed

spec/runners/unified.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'runners/unified/error'
12
require 'runners/unified/entity_map'
23
require 'runners/unified/event_subscriber'
34
require 'runners/unified/test'

spec/runners/unified/assertions.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def assert_result_matches(actual, expected)
3636
if expected_v
3737
if expected_v.empty?
3838
if actual_v && !actual_v.empty?
39-
raise "Actual not empty"
39+
raise Error::ResultMismatch, "Actual not empty"
4040
end
4141
else
4242
if actual_v != expected_v
43-
raise "Mismatch: actual #{actual_v}, expected #{expected_v}"
43+
raise Error::ResultMismatch, "Mismatch: actual #{actual_v}, expected #{expected_v}"
4444
end
4545
end
4646
end
@@ -62,14 +62,14 @@ def assert_outcome
6262
actual_docs = collection.find({}, order: :_id).to_a
6363
assert_documents_match(actual_docs, expected_docs)
6464
unless spec.empty?
65-
raise "Unhandled keys: #{spec}"
65+
raise NotImplementedError, "Unhandled keys: #{spec}"
6666
end
6767
end
6868
end
6969

7070
def assert_documents_match(actual, expected)
7171
unless actual.length == expected.length
72-
raise "Unexpected number of documents: expected #{expected.length}, actual #{actual.length}"
72+
raise Error::ResultMismatch, "Unexpected number of documents: expected #{expected.length}, actual #{actual.length}"
7373
end
7474

7575
actual.each_with_index do |document, index|
@@ -81,7 +81,7 @@ def assert_document_matches(actual, expected, msg)
8181
unless actual == expected
8282
p actual
8383
p expected
84-
raise "#{msg} does not match"
84+
raise Error::ResultMismatch, "#{msg} does not match"
8585
end
8686
end
8787

@@ -95,7 +95,7 @@ def assert_events
9595
expected_events = spec.use!('events')
9696
actual_events = subscriber.wanted_events
9797
unless actual_events.length == expected_events.length
98-
raise "Event count mismatch: expected #{expected_events.length}, actual #{actual_events.length}\nExpected: #{expected_events}\nActual: #{actual_events}"
98+
raise Error::ResultMismatch, "Event count mismatch: expected #{expected_events.length}, actual #{actual_events.length}\nExpected: #{expected_events}\nActual: #{actual_events}"
9999
end
100100
expected_events.each_with_index do |event, i|
101101
assert_event_matches(actual_events[i], event)
@@ -122,22 +122,22 @@ def assert_event_matches(actual, expected)
122122

123123
def assert_eq(actual, expected, msg)
124124
unless expected == actual
125-
raise "#{msg}: expected #{expected}, actual #{actual}"
125+
raise Error::ResultMismatch, "#{msg}: expected #{expected}, actual #{actual}"
126126
end
127127
end
128128

129129
def assert_matches(actual, expected, msg)
130130
if actual.nil? && !expected.nil?
131-
raise "#{msg}: expected #{expected} but got nil"
131+
raise Error::ResultMismatch, "#{msg}: expected #{expected} but got nil"
132132
end
133133

134134
case expected
135135
when Array
136136
unless Array === actual
137-
raise "Expected an array, found #{actual}"
137+
raise Error::ResultMismatch, "Expected an array, found #{actual}"
138138
end
139139
unless actual.length == expected.length
140-
raise "Expected array of length #{expected.length}, found array of length #{actual.length}: #{actual}"
140+
raise Error::ResultMismatch, "Expected array of length #{expected.length}, found array of length #{actual.length}: #{actual}"
141141
end
142142
expected.each_with_index do |v, i|
143143
assert_matches(actual[i], v, "#{msg}: index #{i}")
@@ -166,7 +166,7 @@ def assert_matches(actual, expected, msg)
166166
actual = actual.value
167167
end
168168
unless actual == expected
169-
raise "#{msg}: expected #{expected}, actual #{actual}"
169+
raise Error::ResultMismatch, "#{msg}: expected #{expected}, actual #{actual}"
170170
end
171171
end
172172
end
@@ -182,10 +182,10 @@ def assert_type(object, type)
182182
when 'date'
183183
Time === object
184184
else
185-
raise "Unhandled type #{type}"
185+
raise NotImplementedError, "Unhandled type #{type}"
186186
end
187187
unless ok
188-
raise "Object #{object} is not of type #{type}"
188+
raise Error::ResultMismatch, "Object #{object} is not of type #{type}"
189189
end
190190
end
191191

@@ -198,46 +198,46 @@ def assert_value_matches(actual, expected, msg)
198198
when '$$unsetOrMatches'
199199
if actual
200200
unless actual == expected_v
201-
raise "Mismatch for #{msg}: expected #{expected}, have #{actual}"
201+
raise Error::ResultMismatch, "Mismatch for #{msg}: expected #{expected}, have #{actual}"
202202
end
203203
end
204204
when '$$matchesHexBytes'
205205
expected_data = decode_hex_bytes(expected_v)
206206
unless actual == expected_data
207-
raise "Hex bytes do not match"
207+
raise Error::ResultMismatch, "Hex bytes do not match"
208208
end
209209
when '$$exists'
210210
case expected_v
211211
when true
212212
if actual.nil?
213-
raise "#{msg}: wanted value to exist, but it did not"
213+
raise Error::ResultMismatch, "#{msg}: wanted value to exist, but it did not"
214214
end
215215
when false
216216
if actual
217-
raise "#{msg}: wanted value to not exist, but it did"
217+
raise Error::ResultMismatch, "#{msg}: wanted value to not exist, but it did"
218218
end
219219
else
220-
raise "Bogus value #{expected_v}"
220+
raise NotImplementedError, "Bogus value #{expected_v}"
221221
end
222222
when '$$sessionLsid'
223223
expected_session = entities.get(:session, expected_v)
224224
# TODO - sessions do not expose server sessions after being ended
225225
#unless actual_v == {'id' => expected_session.server_session.session_id.to_bson}
226-
# raise "Session does not match: wanted #{expected_session}, have #{actual_v}"
226+
# raise Error::ResultMismatch, "Session does not match: wanted #{expected_session}, have #{actual_v}"
227227
#end
228228
when '$$type'
229229
assert_type(actual, expected_v)
230230
when '$$matchesEntity'
231231
result = entities.get(:result, expected_v)
232232
unless actual == result
233-
raise "Actual value #{actual} does not match entity #{expected_v} with value #{result}"
233+
raise Error::ResultMismatch, "Actual value #{actual} does not match entity #{expected_v} with value #{result}"
234234
end
235235
else
236-
raise "Unknown operator #{operator}"
236+
raise NotImplementedError, "Unknown operator #{operator}"
237237
end
238238
else
239239
if actual != expected
240-
raise "Mismatch for #{msg}: expected #{expected}, have #{actual}"
240+
raise Error::ResultMismatch, "Mismatch for #{msg}: expected #{expected}, have #{actual}"
241241
end
242242
end
243243
end

spec/runners/unified/crud_operations.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ def insert_many(op)
5454
end
5555
end
5656

57+
def update_one(op)
58+
collection = entities.get(:collection, op.use!('object'))
59+
use_arguments(op) do |args|
60+
collection.update_one(args.use!('filter'), args.use!('update'))
61+
end
62+
end
63+
5764
def replace_one(op)
5865
collection = entities.get(:collection, op.use!('object'))
5966
use_arguments(op) do |args|
@@ -86,7 +93,7 @@ def bulk_write(op)
8693

8794
def convert_bulk_write_spec(spec)
8895
unless spec.keys.length == 1
89-
raise "Must have exactly one item"
96+
raise NotImplementedError, "Must have exactly one item"
9097
end
9198
op, spec = spec.first
9299
spec = UsingHash[spec]
@@ -110,10 +117,10 @@ def convert_bulk_write_spec(spec)
110117
filter: spec.use('filter'),
111118
}
112119
else
113-
raise "Unknown operation #{op}"
120+
raise NotImplementedError, "Unknown operation #{op}"
114121
end
115122
unless spec.empty?
116-
raise "Unhandled keys: #{spec}"
123+
raise NotImplementedError, "Unhandled keys: #{spec}"
117124
end
118125
{Utils.underscore(op) =>out}
119126
end
@@ -123,7 +130,7 @@ def aggregate(op)
123130
args = op.use!('arguments')
124131
pipeline = args.use!('pipeline')
125132
unless args.empty?
126-
raise "Unhandled spec keys: #{test_spec}"
133+
raise NotImplementedError, "Unhandled spec keys: #{test_spec}"
127134
end
128135
obj.aggregate(pipeline).to_a
129136
end

spec/runners/unified/ddl_operations.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def assert_collection_exists(op, state = true)
3434
collection_name = args.use!('collectionName')
3535
if state
3636
unless database.collection_names.include?(collection_name)
37-
raise "Expected collection #{collection_name} to exist, but it does not"
37+
raise Error::ResultMismatch, "Expected collection #{collection_name} to exist, but it does not"
3838
end
3939
else
4040
if database.collection_names.include?(collection_name)
41-
raise "Expected collection #{collection_name} to not exist, but it does"
41+
raise Error::ResultMismatch, "Expected collection #{collection_name} to not exist, but it does"
4242
end
4343
end
4444
end
@@ -82,7 +82,7 @@ def assert_index_not_exists(op)
8282
collection = database[args.use!('collectionName')]
8383
begin
8484
index = collection.indexes.get(args.use!('indexName'))
85-
raise "Index found"
85+
raise Error::ResultMismatch, "Index found"
8686
rescue Mongo::Error::OperationFailure => e
8787
if e.code == 26
8888
# OK

spec/runners/unified/entity_map.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ def initialize
77
def set(type, id, value)
88
@map[type] ||= {}
99
if @map[type][id]
10-
raise "Cannot set #{type} #{id} because it is already defined"
10+
raise Error::EntityMapOverwriteAttempt,
11+
"Cannot set #{type} #{id} because it is already defined"
1112
end
1213
@map[type][id] = value
1314
end
1415

1516
def get(type, id)
1617
unless @map[type]
17-
raise "There are no #{type} entities known"
18+
raise Error::EntityMissing, "There are no #{type} entities known"
1819
end
1920
unless v = @map[type][id]
20-
raise "There is no #{type} #{id} known"
21+
raise Error::EntityMissing, "There is no #{type} #{id} known"
2122
end
2223
v
2324
end
@@ -28,7 +29,7 @@ def get_any(id)
2829
return sub[id]
2930
end
3031
end
31-
raise "There is no #{id} known"
32+
raise Error::EntityMissing, "There is no #{id} known"
3233
end
3334

3435
def [](type)

spec/runners/unified/error.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Unified
2+
3+
class Error < StandardError
4+
5+
class ResultMismatch < Error
6+
end
7+
8+
class ErrorMismatch < Error
9+
end
10+
11+
class UnhandledField < Error
12+
end
13+
14+
class EntityMapOverwriteAttempt < Error
15+
end
16+
17+
class EntityMissing < Error
18+
end
19+
20+
class InvalidTest < Error
21+
end
22+
23+
end
24+
25+
end

spec/runners/unified/event_subscriber.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'support/event_subscriber'
2+
13
module Unified
24

35
class EventSubscriber < ::EventSubscriber

spec/runners/unified/exceptions.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Unified
2+
3+
class Error < StandardError
4+
end
5+
6+
class ResultMismatch < Error
7+
end
8+
9+
class ErrorMismatch < Error
10+
end
11+
12+
class EntityMapOverwriteAttempt < Error
13+
end
14+
15+
class EntityMissing < Error
16+
end
17+
18+
class InvalidTest < Error
19+
end
20+
21+
end

spec/runners/unified/grid_fs_operations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def upload(op)
3939
def transform_contents(contents)
4040
if Hash === contents
4141
if contents.length != 1
42-
raise "Wanted hash with one element"
42+
raise NotImplementedError, "Wanted hash with one element"
4343
end
4444
if contents.keys.first != '$$hexBytes'
45-
raise "$$hexBytes is the only key supported"
45+
raise NotImplementedError, "$$hexBytes is the only key supported"
4646
end
4747

4848
decode_hex_bytes(contents.values.first)

spec/runners/unified/support_operations.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ def assert_same_lsid_on_last_two_commands(op, expected: true)
5858
client = entities.get(:client, args.use!('client'))
5959
subscriber = @subscribers.fetch(client)
6060
unless subscriber.started_events.length >= 2
61-
raise "Must have at least 2 events, have #{subscriber.started_events.length}"
61+
raise Error::ResultMismatch, "Must have at least 2 events, have #{subscriber.started_events.length}"
6262
end
6363
lsids = subscriber.started_events[-2...-1].map do |cmd|
6464
cmd.command.fetch('lsid')
6565
end
6666
if expected
6767
unless lsids.first == lsids.last
68-
raise "lsids differ but they were expected to be the same"
68+
raise Error::ResultMismatch, "lsids differ but they were expected to be the same"
6969
end
7070
else
7171
if lsids.first == lsids.last
72-
raise "lsids are the same but they were expected to be different"
72+
raise Error::ResultMismatch, "lsids are the same but they were expected to be different"
7373
end
7474
end
7575
end
@@ -92,7 +92,7 @@ def assert_session_transaction_state(op)
9292
session = entities.get(:session, args.use!('session'))
9393
state = args.use!('state')
9494
unless session.send("#{state}_transaction?")
95-
raise "Expected session to have state #{state}"
95+
raise Error::ResultMismatch, "Expected session to have state #{state}"
9696
end
9797
end
9898
end
@@ -138,11 +138,11 @@ def assert_session_pinned(op, state = true)
138138

139139
if state
140140
unless session.pinned_server
141-
raise 'Expected session to be pinned but it is not'
141+
raise Error::ResultMismatch, 'Expected session to be pinned but it is not'
142142
end
143143
else
144144
if session.pinned_server
145-
raise 'Expected session to be not pinned but it is'
145+
raise Error::ResultMismatch, 'Expected session to be not pinned but it is'
146146
end
147147
end
148148
end
@@ -156,14 +156,14 @@ def assert_session_unpinned(op)
156156

157157
def assert_no_arguments(op)
158158
if op.key?('arguments')
159-
raise "Arguments are not allowed"
159+
raise NotimplementedError, "Arguments are not allowed"
160160
end
161161
end
162162

163163
def consume_test_runner(op)
164164
v = op.use!('object')
165165
unless v == 'testRunner'
166-
raise 'Expected object to be testRunner'
166+
raise NotImplementedError, 'Expected object to be testRunner'
167167
end
168168
end
169169

0 commit comments

Comments
 (0)