drbrain/net-http-persistent — Issue #13: net-http-persistent incompatible with vcr/fakeweb when reuse_ssl_sessions==true
Author: mbrictson
Created: 2012-01-17 19:07:48+00:00
State: open

By default, net-http-persistent has the option `reuse_ssl_sessions = true`, which causes Net::HTTP::Persistent::SSLReuse to be used as the underlying http class, rather than Net::HTTP. SSLReuse redefines `connect` to use the socket layer directly. The first line is:

```ruby
s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
```

This apparently breaks higher level http mocking libraries. For example, when using the [vcr gem](https://github.com/myronmarston/vcr) with fakeweb mocking, I expect vcr to replay a previously recorded http interaction. Instead, I get an error like this:

```
Net::HTTP::Persistent::Error:
connection refused
```

Currently, my workaround is to prevent net-http-persistent from using the SSLReuse class during tests.

```ruby
http = Net::HTTP::Persistent.new
# Disable SSL pool in test environment, as it breaks fakeweb
http.reuse_ssl_sessions = false if Rails.env.test?
```

Perhaps this there is no other way around this, but I thought I should at least document the problem here, as a Google search did not turn up any other explanations.