Skip to content

Commit 63ea33a

Browse files
authored
Merge pull request #74 from launchdarkly/eb/another-stream-test
unit test for reconnecting after stream EOF
2 parents bc66074 + ea78edf commit 63ea33a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

spec/sse_client/sse_client_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff 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
139177
end

0 commit comments

Comments
 (0)