Skip to content

Commit e0987ee

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 <[email protected]>
1 parent 740f6a7 commit e0987ee

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
@@ -521,12 +521,19 @@ def execute_stream_view_containing_react_components
521521

522522
# Simulate client disconnect by making stream.write raise IOError
523523
call_count = 0
524+
stream_closed = false
524525
allow(mocked_stream).to receive(:write) do |chunk|
525526
call_count += 1
527+
if call_count == 2
528+
stream_closed = true
529+
raise IOError, "client disconnected"
530+
end
526531
written_chunks << chunk
527-
raise IOError, "client disconnected" if call_count == 2
528532
end
529533

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

0 commit comments

Comments
 (0)