Skip to content

Commit bb0baa8

Browse files
committed
For integration tests use create and use a default test store with fixed ID to prevent issues when running parallel mutation tests.
ApplicationController queries for first_available_store_id that can result in differen workers being unable to find the record. Defailt test store is now shared between different mutant workers that should fix the problem.
1 parent 54c8b37 commit bb0baa8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

apps/rails_application/test/test_helper.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def payment_released
130130
end
131131

132132
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"
133135

134136
def before_setup
135137
result = super
@@ -139,7 +141,7 @@ def before_setup
139141
Rails.configuration.command_bus = Arkency::CommandBus.new
140142

141143
Configuration.new.call(Rails.configuration.event_store, Rails.configuration.command_bus)
142-
@default_store_id = register_store("Default Store")
144+
@default_store_id = ensure_default_store
143145
result
144146
end
145147

@@ -235,7 +237,22 @@ def run_command(command)
235237
Rails.configuration.command_bus.call(command)
236238
end
237239

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+
238251
def register_store(name)
252+
# For "Default Store", return the shared test store ID
253+
return DEFAULT_TEST_STORE_ID if name == "Default Store" || name == "Default Test Store"
254+
255+
# For other stores, create normally
239256
store_id = SecureRandom.uuid
240257
post "/admin/stores", params: { store_id: store_id, name: name }
241258
store_id

0 commit comments

Comments
 (0)