Skip to content

Commit 1e5762c

Browse files
committed
Make sure global test store is created before all integration tests by prepending EnsureDefaultStore. This should fix the issue with mutation test neutral failures probably caused by parallel workers using different DB transactions.
1 parent bb0baa8 commit 1e5762c

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

apps/rails_application/test/test_helper.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55

66
ActiveJob::Base.logger = Logger.new(nil)
77

8+
# Shared test store UUID for parallel mutant workers
9+
DEFAULT_TEST_STORE_ID = "00000000-0000-4000-8000-000000000001"
10+
11+
# Global hook to ensure default store exists before ANY test runs
12+
# This runs once per test process, after DB is prepared but before tests start
13+
module EnsureDefaultStore
14+
def before_setup
15+
unless defined?(@@default_store_created)
16+
ActiveRecord::Base.connection.execute(<<-SQL)
17+
INSERT INTO admin_stores (id, name, created_at, updated_at)
18+
VALUES ('#{DEFAULT_TEST_STORE_ID}', 'Default Test Store', NOW(), NOW())
19+
ON CONFLICT (id) DO NOTHING
20+
SQL
21+
@@default_store_created = true
22+
end
23+
super
24+
end
25+
end
26+
27+
# Prepend to all integration tests
28+
ActionDispatch::IntegrationTest.prepend(EnsureDefaultStore)
29+
830
class InMemoryTestCase < ActiveSupport::TestCase
931

1032
def before_setup
@@ -130,9 +152,6 @@ def payment_released
130152
end
131153

132154
class InMemoryRESIntegrationTestCase < ActionDispatch::IntegrationTest
133-
# Shared test store UUID - used by all parallel workers to avoid transaction isolation issues
134-
DEFAULT_TEST_STORE_ID = "00000000-0000-4000-8000-000000000001"
135-
136155
def before_setup
137156
result = super
138157
@previous_event_store = Rails.configuration.event_store
@@ -141,7 +160,7 @@ def before_setup
141160
Rails.configuration.command_bus = Arkency::CommandBus.new
142161

143162
Configuration.new.call(Rails.configuration.event_store, Rails.configuration.command_bus)
144-
@default_store_id = ensure_default_store
163+
@default_store_id = DEFAULT_TEST_STORE_ID
145164
result
146165
end
147166

@@ -237,17 +256,6 @@ def run_command(command)
237256
Rails.configuration.command_bus.call(command)
238257
end
239258

240-
def ensure_default_store
241-
# Create default test store directly in DB, outside of transaction
242-
# This ensures it's visible to all parallel mutant workers
243-
ActiveRecord::Base.connection.execute(<<-SQL)
244-
INSERT INTO admin_stores (id, name, created_at, updated_at)
245-
VALUES ('#{DEFAULT_TEST_STORE_ID}', 'Default Test Store', NOW(), NOW())
246-
ON CONFLICT (id) DO NOTHING
247-
SQL
248-
DEFAULT_TEST_STORE_ID
249-
end
250-
251259
def register_store(name)
252260
# For "Default Store", return the shared test store ID
253261
return DEFAULT_TEST_STORE_ID if name == "Default Store" || name == "Default Test Store"

0 commit comments

Comments
 (0)