Skip to content

Commit 3de5cb5

Browse files
ihabadhamclaude
andcommitted
Fix client disconnect test to properly simulate stream.closed?
The test "stops producing when client disconnects" was failing because the .closed? stub always returned false, so producers never detected the disconnect. Changes: - Add stream_closed flag that starts as false - Set stream_closed = true when IOError is raised (2nd write) - Update .closed? stub to return the stream_closed flag value - Move IOError raise before adding chunk to written_chunks (so written_chunks.count == 1 as expected, not 2) This properly simulates the real behavior where stream.closed? returns true after a write error, allowing producers to detect disconnect and stop producing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d1c9028 commit 3de5cb5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

react_on_rails_pro/spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,19 @@ def execute_stream_view_containing_react_components
520520

521521
# Simulate client disconnect by making stream.write raise IOError
522522
call_count = 0
523+
stream_closed = false
523524
allow(mocked_stream).to receive(:write) do |chunk|
524525
call_count += 1
526+
if call_count == 2
527+
stream_closed = true
528+
raise IOError, "client disconnected"
529+
end
525530
written_chunks << chunk
526-
raise IOError, "client disconnected" if call_count == 2
527531
end
528532

533+
# Update the closed? stub to check the stream_closed flag
534+
allow(mocked_stream).to receive(:closed?) { stream_closed }
535+
529536
# Configure render_to_string to call stream_react_component
530537
allow(self).to receive(:render_to_string) do
531538
render_result = stream_react_component(component_name, props: props, **component_options)

0 commit comments

Comments
 (0)