FIX: Ensure Net::HTTP socket type is StubSocket.#1067
Conversation
|
Getting this error when trying to run tests locally /Users/miketaylor/dev/webmock [master]% bundle exec rake test
/Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/async-http-0.74.0/lib/async/http/endpoint.rb:25:in `<class:Endpoint>': uninitialized constant URI::WSS (NameError)
'wss' => URI::WSS,
^^^^^
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/async-http-0.74.0/lib/async/http/endpoint.rb:20:in `<module:HTTP>'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/async-http-0.74.0/lib/async/http/endpoint.rb:18:in `<module:Async>'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/async-http-0.74.0/lib/async/http/endpoint.rb:17:in `<top (required)>'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/async-http-0.74.0/lib/async/http/internet.rb:8:in `require_relative'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/async-http-0.74.0/lib/async/http/internet.rb:8:in `<top (required)>'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/async-http-0.74.0/lib/async/http.rb:11:in `require_relative'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/async-http-0.74.0/lib/async/http.rb:11:in `<top (required)>'
from /Users/miketaylor/dev/webmock/lib/webmock/http_lib_adapters/async_http_client_adapter.rb:5:in `require'
from /Users/miketaylor/dev/webmock/lib/webmock/http_lib_adapters/async_http_client_adapter.rb:5:in `<top (required)>'
from /Users/miketaylor/dev/webmock/lib/webmock.rb:59:in `require_relative'
from /Users/miketaylor/dev/webmock/lib/webmock.rb:59:in `<top (required)>'
from /Users/miketaylor/dev/webmock/lib/webmock/test_unit.rb:4:in `require'
from /Users/miketaylor/dev/webmock/lib/webmock/test_unit.rb:4:in `<top (required)>'
from /Users/miketaylor/dev/webmock/test/test_helper.rb:6:in `require'
from /Users/miketaylor/dev/webmock/test/test_helper.rb:6:in `<top (required)>'
from /Users/miketaylor/dev/webmock/test/test_webmock.rb:1:in `require'
from /Users/miketaylor/dev/webmock/test/test_webmock.rb:1:in `<top (required)>'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:21:in `require'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:21:in `block in <main>'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:6:in `select'
from /Users/miketaylor/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:6:in `<main>'
rake aborted!
Command failed with status (1)
/Users/miketaylor/.rbenv/versions/3.1.3/bin/bundle:25:in `load'
/Users/miketaylor/.rbenv/versions/3.1.3/bin/bundle:25:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace) |
|
@sealabcore Thank you for your work on this PR. I've noticed that while the tests in master are now passing, there aren't any new tests associated with this specific change. Could you please provide some context on why this particular modification is necessary? I'm especially interested in understanding the rationale behind assigning Given the lack of new tests, could you explain how we can be confident that this change works as intended and doesn't introduce any regressions? Perhaps you could suggest some test cases that would effectively validate this new behavior? |
|
Thought I'd bump this because we ran into this error with our app recently as well. (Same exception from the same line in webmock, though the rest of the stack was a bit different because we're using it with capybara + selenium.) For us, the error was happening when enabling WebMock, then disabling it, but continuing to use a cached instance of the mocked version of After WebMock has been disabled, (the real implementation of) I'm not super familiar with WebMock's internals, but if I'm understanding well enough I think it would be appropriate (and a little simpler than the change in this PR) for We ended up finding a different way to mock remote APIs in tests and removing WebMock from those tests, but I went back and tested a version using Hope this is helpful for you @bblimke. |
When running my tests related to opensearch using the searchkick gem I was getting intermittent errors from the Webmock library as seen below. After some debug logging I noticed that
StubSocketwasn't always theNet::HTTP.socket_typeas expected. This change ensures the socket_type is alwaysStubSocketas opposed toNet::BufferedIO.ankane/searchkick#1692