Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add exclusion of transact test by name
Browse files Browse the repository at this point in the history
BuonOmo committed Dec 18, 2024
1 parent 3067576 commit 86dbe4c
Showing 5 changed files with 50 additions and 11 deletions.
5 changes: 5 additions & 0 deletions test/cases/helper_cockroachdb.rb
Original file line number Diff line number Diff line change
@@ -37,6 +37,11 @@ def load_schema
# Load ActiveRecord test helper
require "cases/helper"

require "support/exclude_from_transactional_tests"

# Allow exclusion of tests by name using #exclude_from_transactional_tests(test_name)
ActiveRecord::TestCase.prepend(ExcludeFromTransactionalTests)

# Load the CockroachDB specific schema. It replaces ActiveRecord's PostgreSQL
# specific schema.
def load_cockroachdb_specific_schema
2 changes: 1 addition & 1 deletion test/cases/show_create_test.rb
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ class ShowCreateTest < ActiveRecord::TestCase
fixtures :posts

def test_show_create
assert_match /CREATE TABLE public\.posts/, Post.show_create
assert_match(/CREATE TABLE public\.posts/, Post.show_create)
end
end
end
8 changes: 8 additions & 0 deletions test/excludes/EachTest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "support/copy_cat"

# CockroachDB doesn't update schema information when adding an
# index until the transaction is done. Hence impossible to delete
# this index before completion of the transaction.
exclude_from_transactional_tests :test_in_batches_iterating_using_custom_columns
exclude_from_transactional_tests :test_in_batches_with_custom_columns_raises_when_non_unique_columns
exclude_from_transactional_tests :test_in_batches_when_loaded_iterates_using_custom_column
12 changes: 2 additions & 10 deletions test/excludes/MultiDbMigratorTest.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
require "support/copy_cat"

class CockroachDB < MultiDbMigratorTest
self.use_transactional_tests = false

CopyCat.copy_methods(self, MultiDbMigratorTest, :test_internal_metadata_stores_environment)
end

exclude :test_internal_metadata_stores_environment, "We can't add " \
"and remove a column in the same transaction with CockroachDB"
# We can't add and remove a column in the same transaction with CockroachDB
exclude_from_transactional_tests :test_internal_metadata_stores_environment
34 changes: 34 additions & 0 deletions test/support/exclude_from_transactional_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

# Allow exclusion of tests by name using #exclude_from_transactional_tests(test_name)
module ExcludeFromTransactionalTests
module ClassMethods
def exclude_from_transactional_tests(name)
@non_transactional_list ||= []
@non_transactional_list << name.to_s
end

def non_transactional_list
@non_transactional_list ||= []
end
end

def self.prepended(base)
base.extend ClassMethods
end

def before_setup
# binding.irb if self.class.non_transactional_list.include?(@NAME.to_s)
@old_use_transactional_tests = self.use_transactional_tests
if @old_use_transactional_tests # stay false if false
self.use_transactional_tests = !self.class.non_transactional_list.include?(@NAME.to_s)
end
super
end

def after_teardown
super
ensure
self.use_transactional_tests = @old_use_transactional_tests
end
end

0 comments on commit 86dbe4c

Please sign in to comment.