File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -136,4 +136,42 @@ def with_client(client)
136136 end
137137 end
138138 end
139+
140+ it "reconnects if stream returns EOF" do
141+ events_body_1 = <<-EOT
142+ event: go
143+ data: foo
144+
145+ EOT
146+ events_body_2 = <<-EOT
147+ event: go
148+ data: bar
149+
150+ EOT
151+ with_server do |server |
152+ attempt = 0
153+ server . setup_response ( "/" ) do |req , res |
154+ attempt += 1
155+ if attempt == 1
156+ res . body = events_body_1
157+ else
158+ res . body = events_body_2
159+ end
160+ res . content_type = "text/event-stream"
161+ res . status = 200
162+ end
163+
164+ event_sink = Queue . new
165+ client = subject . new ( server . base_uri ,
166+ reconnect_time : 0.25 , read_timeout : 0.25 ) do |c |
167+ c . on_event { |event | event_sink << event }
168+ end
169+
170+ with_client ( client ) do |client |
171+ expect ( event_sink . pop ) . to eq ( SSE ::SSEEvent . new ( :go , "foo" , nil ) )
172+ expect ( event_sink . pop ) . to eq ( SSE ::SSEEvent . new ( :go , "bar" , nil ) )
173+ expect ( attempt ) . to be >= 2
174+ end
175+ end
176+ end
139177end
You can’t perform that action at this time.
0 commit comments