Skip to content
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

WebMock breaks Async::WebSocket #953

Open
zhulik opened this issue Aug 30, 2021 · 4 comments
Open

WebMock breaks Async::WebSocket #953

zhulik opened this issue Aug 30, 2021 · 4 comments

Comments

@zhulik
Copy link

zhulik commented Aug 30, 2021

Hello,

I'm currently working on a project that uses Async::WebSocket to interact with a database running locally and Async::HTTP to call some 3rd party services.

I wanted to use WebMock to prevent the test suite from making any network requests, but allow it to interact with the database.

An attempt to open a websocket connection with enabled WebMock blocking leads to an error:

     3.2) Failure/Error: Async::WebSocket::Client.connect(endpoint)
          
          NoMethodError:
            undefined method `acquire' for nil:NilClass
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/async-websocket-0.19.0/lib/async/websocket/client.rb:93:in `connect'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/async-websocket-0.19.0/lib/async/websocket/client.rb:53:in `connect'
          # ./spec/demo_spec.rb:74:in `block (4 levels) in <top (required)>'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/lib/rspec/core/example.rb:262:in `instance_exec'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/lib/rspec/core/example.rb:262:in `block in run'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/lib/rspec/core/example.rb:508:in `block in with_around_and_singleton_context_hooks'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/lib/rspec/core/example.rb:465:in `block in with_around_example_hooks'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/lib/rspec/core/hooks.rb:486:in `block in run'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/lib/rspec/core/example.rb:350:in `call'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/async-rspec-1.16.1/lib/async/rspec/reactor.rb:93:in `block (4 levels) in <module:RSpec>'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/async-rspec-1.16.1/lib/async/rspec/reactor.rb:57:in `block in run_in_reactor'
          # /home/zhulik/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/async-1.30.1/lib/async/task.rb:260:in `block in make_fiber'

It is expected that WebMock should not care about websockets, but at least it should not break them if the host is in the allowlist.

I prepared a minimal demo app that reproduces this error: https://github.com/zhulik/async-http-webmock-bug-demo

Thanks you!

@zhulik zhulik changed the title WebMock breaks Async::Websocket WebMock breaks Async::WebSocket Aug 30, 2021
@zhulik
Copy link
Author

zhulik commented Aug 30, 2021

@ioquatix would you mind having a look? Maybe the problem is somewhere in the Async stack

@ioquatix
Copy link
Contributor

Sure.

@odlp
Copy link

odlp commented May 9, 2024

Also running into this issue and would love to help working towards a fix.

I'm not too familiar with Async so probably wouldn't be much help directly fixing the bug, but if a repro script would be useful please let me know.

@ioquatix
Copy link
Contributor

ioquatix commented May 9, 2024

Mocking async-http can be complicated due to the nature of the internal implementation and the full support for streaming, web sockets, proxies, etc.

The plan is to introduce a mechanism for redirecting / mocking requests directly in Async::HTTP: socketry/async-http#41

It will require some more work, but I think the plan is to provide a hook such that web mock can say "I'll hijack requests with this middleware" and handle them using a standard interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants