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

Feat: VCR support catching NetHttp2 requests #1021

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

joaoGabriel55
Copy link

@joaoGabriel55 joaoGabriel55 commented Jul 19, 2024

Issue: #976

Provide VCR support to catch NetHttp2 requests like Faraday and Webmock.

Gemfile Outdated Show resolved Hide resolved
@olleolleolle olleolleolle linked an issue Jul 19, 2024 that may be closed by this pull request
@olleolleolle
Copy link
Member

@joaoGabriel55 Thanks for taking a stab at implementing this! Please do continue, it looks promising.

Copy link
Contributor

@andrehjr andrehjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also some cucumber for middleware here

Though, it seems like they haven't been updated for a while 🤔

module Middleware
# Object yielded by VCR's {NetHttp2} middleware that allows you to configure
# the cassette dynamically based on the rack env.
class CassetteArguments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This part looks duplicated from lib/vcr/middleware/rack.rb maybe we can extract something to avoid duplication?

@olleolleolle
Copy link
Member

I recorded #1022 as a sign-post issue that it's known that that test fails. Not the fault of this change.

@olleolleolle
Copy link
Member

@joaoGabriel55 Can you rebase on master branch? There've been some changes, which may help the CI run.

@olleolleolle
Copy link
Member

olleolleolle commented Jul 23, 2024

So, the current CI run has this failure.

I have included the backtrace and the messages. The backtrace mentions net-http2/client.rb, whereas the driver mentioned is typhoeus:

Failures:

  1) VCR::Middleware::Faraday behaves like a hook into an HTTP library using Faraday (typhoeus) when VCR.real_http_connections_allowed? is returning false when ignore_hosts is configured to "127.0.0.1", "localhost" allows requests to localhost
     Failure/Error: raise exception

     SocketError:
       Socket was remotely closed
     Shared Example Group: "a hook into an HTTP library" called from ./spec/lib/vcr/middleware/faraday_spec.rb:12
     # ./vendor/bundle/ruby/3.0.0/gems/net-http2-0.18.5/lib/net-http2/client.rb:134:in `callback_or_raise'
     # ./vendor/bundle/ruby/3.0.0/gems/net-http2-0.18.5/lib/net-http2/client.rb:119:in `rescue in block (2 levels) in ensure_open'
     # ./vendor/bundle/ruby/3.0.0/gems/net-http2-0.18.5/lib/net-http2/client.rb:113:in `block (2 levels) in ensure_open'
     # ------------------
     # --- Caused by: ---
     # EOFError:
     #   end of file reached
     #   ./vendor/bundle/ruby/3.0.0/gems/net-http2-0.18.5/lib/net-http2/client.rb:145:in `block in socket_loop'

  2) VCR::Middleware::Faraday behaves like a hook into an HTTP library using Faraday (typhoeus) request hooks when the request is ignored behaves like request hooks the before_http_request hook is not called if the library hook is disabled
     Failure/Error: raise exception

     SocketError:
       Socket was remotely closed
     Shared Example Group: "request hooks" called from ./spec/support/shared_example_groups/hook_into_http_library.rb:340
     Shared Example Group: "a hook into an HTTP library" called from ./spec/lib/vcr/middleware/faraday_spec.rb:12
     # ./vendor/bundle/ruby/3.0.0/gems/net-http2-0.18.5/lib/net-http2/client.rb:134:in `callback_or_raise'
     # ./vendor/bundle/ruby/3.0.0/gems/net-http2-0.18.5/lib/net-http2/client.rb:119:in `rescue in block (2 levels) in ensure_open'
     # ./vendor/bundle/ruby/3.0.0/gems/net-http2-0.18.5/lib/net-http2/client.rb:113:in `block (2 levels) in ensure_open'
     # ------------------
     # --- Caused by: ---
     # EOFError:
     #   end of file reached
     #   ./vendor/bundle/ruby/3.0.0/gems/net-http2-0.18.5/lib/net-http2/client.rb:145:in `block in socket_loop'

Finished in 15.36 seconds (files took 1.05 seconds to load)
2006 examples, 2 failures, 1 pending

Failed examples:

rspec './spec/lib/vcr/middleware/faraday_spec.rb[1:1:1:13:2:2]' # VCR::Middleware::Faraday behaves like a hook into an HTTP library using Faraday (typhoeus) when VCR.real_http_connections_allowed? is returning false when ignore_hosts is configured to "127.0.0.1", "localhost" allows requests to localhost
rspec './spec/lib/vcr/middleware/faraday_spec.rb[1:1:1:10:3:1:3]' # VCR::Middleware::Faraday behaves like a hook into an HTTP library using Faraday (typhoeus) request hooks when the request is ignored behaves like request hooks the before_http_request hook is not called if the library hook is disabled

@joaoGabriel55
Copy link
Author

joaoGabriel55 commented Jul 25, 2024

spec/lib/vcr/middleware/faraday_spec.rb

Strange. I ran the command bundle exec rake locally and all the specs passed. It seems like we might have a flaky test.

Copy link
Contributor

@andrehjr andrehjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the specs are failing because:

lib/vcr/middleware/rack.rb:7: warning: method redefined; discarding old initialize
lib/vcr/middleware/net_http2.rb:14: warning: previous definition of initialize was here
lib/vcr/middleware/rack.rb:16: warning: method redefined; discarding old name
lib/vcr/middleware/net_http2.rb:23: warning: previous definition of name was here
lib/vcr/middleware/rack.rb:25: warning: method redefined; discarding old options
lib/vcr/middleware/net_http2.rb:32: warning: previous definition of options was here

So, I think those need to be addressed first. I'm not sure that we can hook into net_http2 the same way we do for 'Rack' though 🤔

Were you able to record any response with net-http2?

@joaoGabriel55
Copy link
Author

joaoGabriel55 commented Aug 7, 2024

Right now the specs are failing because:

lib/vcr/middleware/rack.rb:7: warning: method redefined; discarding old initialize
lib/vcr/middleware/net_http2.rb:14: warning: previous definition of initialize was here
lib/vcr/middleware/rack.rb:16: warning: method redefined; discarding old name
lib/vcr/middleware/net_http2.rb:23: warning: previous definition of name was here
lib/vcr/middleware/rack.rb:25: warning: method redefined; discarding old options
lib/vcr/middleware/net_http2.rb:32: warning: previous definition of options was here

So, I think those need to be addressed first. I'm not sure that we can hook into net_http2 the same way we do for 'Rack' though 🤔

Were you able to record any response with net-http2?

I created a simple rails-app to test that and is not recording net-http2 response. I am investing this

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

Successfully merging this pull request may close these issues.

VCR not catching NetHttp2 requests
3 participants