-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example for Cucumber step definitions #66
Comments
Using an around hook instead of a single step works correctly without warning. Around("@connected") do |scenario, block|
Async do
@endpoint = Async::HTTP::Endpoint.parse("ws://127.0.0.1:3000")
Async::WebSocket::Client.connect(@endpoint) do |connection|
@connection = connection
block.call
end
end
end I guess this is because The following works as well Around("@connected") do |scenario, block|
Async do
@endpoint = Async::HTTP::Endpoint.parse("ws://127.0.0.1:3000")
@connection = Async::WebSocket::Client.connect(@endpoint)
block.call
ensure
@connection.close
end
end And this more generic version works as well. Given(/^the client is connected to the relay$/) do
@endpoint = Async::HTTP::Endpoint.parse("ws://127.0.0.1:3000")
@connection = Async::WebSocket::Client.connect(@endpoint)
end
Around do |scenario, block|
Async do
block.call
ensure
@connection&.close
end
end |
As you figured out, the connection is closed automatically when it goes out of scope. But the connection is still in use by the WebSocket instance. So, a warning is issued that we are closing the HTTP connection while it still appears to be in use (i.e. not checked back into the connection pool). As you implemented, calling
Does that answer your question? |
Yes, thank you very much!
# features/support/env.rb
Around do |_scenario, block|
Async { block.call }
end
# features/step_definitions/connection.rb
Given(/^the client is connected to the relay$/) do
@endpoint = Async::HTTP::Endpoint.parse("ws://127.0.0.1:3000")
@connection = Async::WebSocket::Client.connect(@endpoint)
end
After do
@connection&.close
end |
I've got the following Cucumber step definitions implemented:
Running them returns the following stdout:
The assertion passes. Everything works as expected. But I don't like this warning. Where does this come from?
The text was updated successfully, but these errors were encountered: