diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 4c502ad..4a27223 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -32,6 +32,8 @@ def with_client(client) yield client ensure client.close + # Wait for SSE worker thread to terminate before next test reuses the port + Thread.list.select { |t| t.name == 'LD/SSEClient' }.each { |t| t.join(1) } end end @@ -1124,7 +1126,7 @@ def test_object.to_s requests << request_data attempt += 1 if attempt == 1 - send_stream_content(res, "", keep_open: false) # Close to trigger reconnect + send_stream_content(res, ": keepalive\n\n", keep_open: false) # Close to trigger reconnect else send_stream_content(res, "", keep_open: true) end @@ -1334,9 +1336,7 @@ def test_object.to_s requests << request_data attempt += 1 if attempt <= 2 - res.status = 500 - res.body = "error" - res.keep_alive = false + send_stream_content(res, ": ping\n\n", keep_open: false) # Close to trigger reconnect else send_stream_content(res, "", keep_open: true) end diff --git a/spec/headers_spec.rb b/spec/headers_spec.rb index 007f25b..c0c3d77 100644 --- a/spec/headers_spec.rb +++ b/spec/headers_spec.rb @@ -18,6 +18,8 @@ def with_client(client) yield client ensure client.close + # Wait for SSE worker thread to terminate before next test reuses the port + Thread.list.select { |t| t.name == 'LD/SSEClient' }.each { |t| t.join(1) } end end