Problem
Several tests use Process.sleep for synchronization instead of message-based waiting (assert_receive, MockCLI.poll_until, etc.). These are brittle and can fail on slow or fast CI runners.
Additionally, some assertions are effectively meaningless due to overly loose conditions.
Affected Tests
Process.sleep used for synchronization
test/claude_code/session_test.exs (lines 110, 118, 311, 324, 453, 461, 811, 851)
Process.sleep(50) between action and state inspection
- Should use
assert_receive or poll-based waiting
test/claude_code_test.exs (lines 197, 213)
Process.sleep(100) after stop() before checking Process.alive?
- Should poll or use monitor-based waiting
test/claude_code/supervisor_test.exs (lines 65, 115, 211, 237, 264)
Process.sleep(100) for supervisor restart/shutdown timing
- Should use
assert_receive on supervisor events or poll child counts
Meaningless assertions
test/claude_code/supervisor_test.exs (line 117)
assert ClaudeSupervisor.count_sessions(supervisor) >= 0 — always true, provides no test value
- Should assert a specific expected count or use polling to wait for a known state
Recommended Approach
The codebase already has a good pattern in port_test.exs using MockCLI.poll_until:
MockCLI.poll_until(fn ->
state = :sys.get_state(adapter)
if condition_met?(state), do: {:ok, state}, else: :retry
end, timeout: 5000)
Replace Process.sleep + assertion pairs with this pattern or assert_receive where applicable.
Problem
Several tests use
Process.sleepfor synchronization instead of message-based waiting (assert_receive,MockCLI.poll_until, etc.). These are brittle and can fail on slow or fast CI runners.Additionally, some assertions are effectively meaningless due to overly loose conditions.
Affected Tests
Process.sleep used for synchronization
test/claude_code/session_test.exs(lines 110, 118, 311, 324, 453, 461, 811, 851)Process.sleep(50)between action and state inspectionassert_receiveor poll-based waitingtest/claude_code_test.exs(lines 197, 213)Process.sleep(100)afterstop()before checkingProcess.alive?test/claude_code/supervisor_test.exs(lines 65, 115, 211, 237, 264)Process.sleep(100)for supervisor restart/shutdown timingassert_receiveon supervisor events or poll child countsMeaningless assertions
test/claude_code/supervisor_test.exs(line 117)assert ClaudeSupervisor.count_sessions(supervisor) >= 0— always true, provides no test valueRecommended Approach
The codebase already has a good pattern in
port_test.exsusingMockCLI.poll_until:Replace
Process.sleep+ assertion pairs with this pattern orassert_receivewhere applicable.