Skip to content

Commit fc08d8a

Browse files
committed
fix(test): flaky test_truncate_tables_with_query_cache
This fixes a bug where our `TestRetryHelper` logic combined with `reset_fixtures` trying to reset a table without foreign keys from another table. It would first crash, removing the foreign key constraint (due to how we handle `disable_referential_integrity`). And then pass, since the foreign key constraint is gone. But we need that constraint in later tests.
1 parent dbc3bc4 commit fc08d8a

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
11
exclude :test_reset_empty_table_with_custom_pk, "The test fails because serial primary keys in CockroachDB are created with unique_rowid() where PostgreSQL will create them with a sequence. See https://www.cockroachlabs.com/docs/v19.2/serial.html#modes-of-operation"
2+
3+
require "support/copy_cat"
4+
5+
# This fixes a bug where our `TestRetryHelper` logic combined
6+
# with `reset_fixtures` trying to reset a table without foreign
7+
# keys from another table.
8+
# It would first crash, removing the foreign key constraint (due
9+
# to how we handle `disable_referential_integrity`). And then pass,
10+
# since the foreign key constraint is gone. But we need that
11+
# constraint in later tests.
12+
CopyCat.copy_methods(self, self, :reset_fixtures) do
13+
def on_block(node)
14+
return unless node in [:block, [:send, [:lvar, :fixture_names], :each], *]
15+
16+
replace(node.loc.expression, "ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, fixture_names)")
17+
end
18+
end

test/excludes/PostgreSQLReferentialIntegrityTest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
exclude :test_should_reraise_invalid_foreign_key_exception_and_show_warning,
2-
"CockroachDB has a different limitation as there is no" \
2+
"CockroachDB has a different limitation as there is no " \
33
"'DISABLE TRIGGER' statement."
44

55
break_tx = "CockroachDB will always alter transactions when " \

test/support/copy_cat.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def warn(message, category: nil, **kwargs)
2525
# Once debug is set, you can check the closest node you want to edit
2626
# and then create a method `on_<node_type>` to handle it.
2727
def copy_methods(new_klass, old_klass, *methods, debug: false, &block)
28+
if debug and not block_given?
29+
puts "You need to provide a block to debug."
30+
end
2831
methods.each do |met|
2932
file, _ = old_klass.instance_method(met).source_location
3033
ast = find_method(Prism::Translation::Parser.parse_file(file), met)

0 commit comments

Comments
 (0)