spec/support/crud.rb in mongo-2.5.0.beta vs spec/support/crud.rb in mongo-2.5.0
- old
+ new
@@ -101,33 +101,17 @@
end
private
def upper_bound_satisfied?(client)
- if @max_server_version
- if @max_server_version < '2.6'
- !client.cluster.next_primary.features.write_command_enabled?
- end
- else
- true
- end
+ return true unless @max_server_version
+ client.database.command(buildInfo: 1).first['version'] <= @max_server_version
end
def lower_bound_satisfied?(client)
- if @min_server_version
- if @min_server_version >= '3.6'
- client.cluster.next_primary.features.array_filters_enabled?
- elsif @min_server_version >= '3.4'
- client.cluster.next_primary.features.collation_enabled?
- elsif @min_server_version >= '2.6'
- client.cluster.next_primary.features.write_command_enabled?
- else
- true
- end
- else
- true
- end
+ return true unless @min_server_version
+ @min_server_version <= client.database.command(buildInfo: 1).first['version']
end
end
# Represents a single CRUD test.
#
@@ -139,10 +123,12 @@
# @return [ String ] description The test description.
#
# @since 2.0.0
attr_reader :description
+ FAIL_POINT_BASE_COMMAND = { configureFailPoint: "onPrimaryTransactionalWrite" }
+
# Instantiate the new CRUDTest.
#
# @example Create the test.
# CRUDTest.new(data, test)
#
@@ -151,10 +137,11 @@
# @param [ Hash ] test The test specification.
#
# @since 2.0.0
def initialize(data, test)
@data = data
+ @fail_point_command = FAIL_POINT_BASE_COMMAND.merge(test['failPoint']) if test['failPoint']
@description = test['description']
@operation = Operation.get(test['operation'])
@outcome = test['outcome']
end
@@ -168,15 +155,31 @@
#
# @return [ Result, Array<Hash> ] The result(s) of running the test.
#
# @since 2.0.0
def run(collection)
- @collection = collection
- @collection.insert_many(@data)
@operation.execute(collection)
end
+ def setup_test(collection)
+ clear_fail_point(collection)
+ @collection = collection
+ collection.delete_many
+ collection.insert_many(@data)
+ set_up_fail_point(collection)
+ end
+
+ def set_up_fail_point(collection)
+ collection.client.use(:admin).command(@fail_point_command) if @fail_point_command
+ end
+
+ def clear_fail_point(collection)
+ if @fail_point_command
+ collection.client.use(:admin).command(FAIL_POINT_BASE_COMMAND.merge(mode: "off"))
+ end
+ end
+
# The expected result of running the test.
#
# @example Get the expected result of running the test.
# test.result
#
@@ -239,19 +242,24 @@
# @since 2.4.0
def outcome_collection_data
@outcome['collection']['data'] if @outcome['collection']
end
+ def error?
+ !!@outcome['error']
+ end
+
private
def compare_result(expected, actual)
case expected
when nil
actual.nil?
when Hash
- actual.all? do |k, v|
- expected[k] == v || handle_upserted_id(k, expected[k], v)
+ results = actual.instance_variable_get(:@results)
+ (results || actual).all? do |k, v|
+ expected[k] == v || handle_upserted_id(k, expected[k], v) || handle_inserted_ids(k, expected[k], v)
end
when Integer
expected == actual
end
end
@@ -260,9 +268,15 @@
return true if expected_id.nil?
if field == 'upsertedId'
if expected_id.is_a?(Integer)
actual_id.is_a?(BSON::ObjectId) || actual_id.nil?
end
+ end
+ end
+
+ def handle_inserted_ids(field, expected, actual)
+ if field == 'insertedIds'
+ expected.values == actual
end
end
def actual_collection_data
if @outcome['collection']