Fix ArgumentError from TestFixtures setup_shared_connection_pool#379
Merged
Fix ArgumentError from TestFixtures setup_shared_connection_pool#379
Conversation
… setup Rails' setup_shared_connection_pool assumes every registered shard has a :writing pool_config; Apartment's role-keyed tenant shards violate this, raising ArgumentError. This module strips tenant pools from the ConnectionHandler and PoolManager before super runs, with a re-entrant guard to prevent double-cleanup from AR's notification subscriber. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…_pools! - Add boolean validation for test_fixture_cleanup in Config#validate! (matches pattern of all other boolean config attributes) - Extract public Apartment.reset_tenant_pools! method encapsulating the three-step cleanup (deregister + clear + reset) - Update TestFixtures to call the public API instead of send(:deregister_all_tenant_pools) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous review-fix commit (8fabf00) accidentally reverted the Railtie wiring added in 35eda8c. The hook was lost because the working tree had a stale railtie.rb when the review fixes were staged. Without this hook, test_fixture_cleanup config is validated but never read, and downstream apps don't get the automatic cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Restore config_spec default assertion for test_fixture_cleanup (lost in external file modification) - Add comment explaining re-entry test is a unit-level approximation of the !connection.active_record subscriber scenario - Improve YARD doc on reset_tenant_pools! for discoverability Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mnovelo
added a commit
that referenced
this pull request
Apr 11, 2026
PR #379 guarded cleanup but still called super on re-entry. When the !connection.active_record subscriber fires mid-test (after the elevator creates a tenant pool), super iterates shard_names and crashes on the apartment shard that has no :writing pool_config. Fix: return early (skip both cleanup AND super) when the guard is set. Apartment pools should not participate in Rails' writing/reading pool config swap; the subscriber still pins and leases the connection independently. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
mnovelo
added a commit
that referenced
this pull request
Apr 11, 2026
* Fix TestFixtures subscriber re-entry crash (Trigger B) PR #379 guarded cleanup but still called super on re-entry. When the !connection.active_record subscriber fires mid-test (after the elevator creates a tenant pool), super iterates shard_names and crashes on the apartment shard that has no :writing pool_config. Fix: return early (skip both cleanup AND super) when the guard is set. Apartment pools should not participate in Rails' writing/reading pool config swap; the subscriber still pins and leases the connection independently. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Clarify guard comment: first call vs re-entry behavior Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ArgumentError: pool_config for :reading role and :apartment_...:reading shard was nilcaused by Rails'setup_shared_connection_pooliterating apartment's role-specific tenant shardson_load(:active_record_fixtures)hook, matchingactiverecord-tenanted's precedent for fixture integration!connection.active_recordnotification subscriber mid-exampleProblem
Rails'
ActiveRecord::TestFixtures#setup_shared_connection_poolassumes every shard has a:writingpool_config. Apartment v4 registers tenant pools under role-specific custom shard keys (e.g., shard:apartment_acme:readingunder role:reading). When fixture setup encounters this shard,writing_pool_configresolves to nil, andset_pool_config(role, shard, nil)raisesArgumentError.Surfaces when a
before(:all)block (or prior test) triggers the elevator underconnected_to(role: :reading), creating a tenant pool, and a subsequent example's fixture setup discovers and iterates it.Changes
lib/apartment/test_fixtures.rbApartment::TestFixturesmodule: overridessetup_shared_connection_poolto deregister apartment pools before Rails iterates themlib/apartment/railtie.rbon_load(:active_record_fixtures)hook, guarded byRails.env.test?andconfig.test_fixture_cleanuplib/apartment/config.rbtest_fixture_cleanupattribute (defaulttrue) — escape hatch to disablespec/unit/test_fixtures_spec.rbdocs/designs/v4-test-fixtures-compatibility.mddocs/plans/apartment-v4/test-fixtures-compatibility.mdTest plan
bundle exec appraisal rails-8.1-sqlite3 rspec spec/unit/test_fixtures_spec.rb— 6 examples, 0 failuresbundle exec appraisal rails-8.0-sqlite3 rspec spec/unit/test_fixtures_spec.rb— 6 examples, 0 failuresbundle exec appraisal rails-8.1-sqlite3 rspec spec/unit/— 688 examples, 0 failuresbundle exec rubocopon all changed files — no offenses🤖 Generated with Claude Code