Pooling Test Fix Plan
Overview
This document outlines the specific fixes needed to resolve the 20 integration test failures introduced by the pooling implementation.
Fix Categories
1. Port Mock Implementation (Priority: High)
Affected Tests: PoolWorker tests 1-6
Issue: Tests use self()
as mock port, but code calls Port.connect
which requires real Port
Solutions:
Option A: Modify PoolWorker to check if port is actually a Port before calling connect
if is_port(port) do Port.connect(port, self()) end
Option B: Create a proper MockPort that doesn’t use Port.connect
- Already have
DSPex.Test.MockPort
module - Need to update PoolWorker tests to use it properly
- Already have
Option C: Add a test mode flag to skip Port.connect in tests
2. Dynamic Pool Naming (Priority: High)
Affected Tests: SessionPool tests 7-14 Issue: Fixed pool name causes conflicts between tests
Solution:
Modify SessionPool to accept pool name in options:
def start_link(opts) do name = Keyword.get(opts, :name, __MODULE__) pool_name = Keyword.get(opts, :pool_name, :"#{name}_pool") # Use pool_name for NimblePool registration end
Update
pool_name/0
to use state-based name:defp pool_name(name) do :"#{name}_pool" end
3. Health Status Alignment (Priority: High)
Affected Tests: PoolWorker tests 1, 4, 6
Issue: Tests expect :ready
but implementation uses :healthy
Solution:
- Update test expectations to use correct status values:
:ready
→:healthy
:initializing
stays the same- Add
:degraded
status handling
4. Supervision Tree Setup (Priority: High)
Affected Tests: Integration tests 15-20 Issue: Python bridge not available in test environment
Solutions:
For Layer 3 tests: Ensure proper supervisor starts based on configuration
- Check if pooling is enabled in config
- Start appropriate supervisor (pooled vs single)
Update test_helper.exs: Add pooling mode configuration
case System.get_env("TEST_MODE") do "full_integration" -> # Start pooling supervisor for integration tests Application.put_env(:dspex, :pooling_enabled, true) _ -> # Use single instance for other tests Application.put_env(:dspex, :pooling_enabled, false) end
Conditional supervisor: Make ConditionalSupervisor check pooling config
5. Adapter Factory Updates (Priority: Medium)
Affected Tests: Adapter compliance tests 16-20 Issue: Factory returns PythonPool adapter but pool isn’t initialized
Solution:
- Update factory to check if pooling is available:
defp resolve_adapter(:layer_3) do if pooling_enabled?() and pool_available?() do DSPex.Adapters.PythonPool else DSPex.Adapters.PythonPort end end
Implementation Order
- Fix health status values (quick fix)
- Add dynamic pool naming (prevents test conflicts)
- Fix port mock implementation (unblocks PoolWorker tests)
- Update supervision setup (enables integration tests)
- Update adapter factory (completes integration)
Test Categories After Fix
Layer 1 (Mock Tests)
- Should not start any Python processes
- Use mock adapters only
- No pooling infrastructure needed
Layer 2 (Bridge Mock Tests)
- Use mock ports that don’t require Port.connect
- Test protocol and communication logic
- No real Python processes
Layer 3 (Integration Tests)
- Start real Python processes
- Use either pooled or single-instance mode
- Full integration testing
Configuration Strategy
Add configuration to control pooling:
config :dspex,
pooling_enabled: false, # Default for tests
pool_size: 2, # Small pool for tests
pool_mode: :test # Special test mode
For production:
config :dspex,
pooling_enabled: true,
pool_size: System.schedulers_online() * 2,
pool_mode: :production