|
95 | 95 | it "errors if connecting takes too long" do
|
96 | 96 | socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
97 | 97 |
|
98 |
| - fake_socket = double(:to_io => socket) |
99 |
| - expect(fake_socket).to receive(:connect_nonblock) do |*args| |
| 98 | + fake_socket_id = double(:to_io => socket) |
| 99 | + expect(fake_socket_id).to receive(:connect_nonblock) do |*args| |
100 | 100 | sleep 1.25
|
101 | 101 | socket.connect_nonblock(*args)
|
102 | 102 | end
|
103 | 103 |
|
104 |
| - allow_any_instance_of(timeout_class).to receive(:socket).and_return(fake_socket) |
| 104 | + allow_any_instance_of(timeout_class).to receive(:socket).and_return(fake_socket_id) |
105 | 105 |
|
106 | 106 | expect { response }.to raise_error(HTTP::TimeoutError, /Timed out/)
|
107 | 107 | end
|
|
148 | 148 | expect(sockets_used.uniq.length).to eq(1)
|
149 | 149 | end
|
150 | 150 |
|
| 151 | + context "on a mixed state" do |
| 152 | + it "re-opens the connection" do |
| 153 | + first_socket_id = client.get("#{server.endpoint}/socket/1").body.to_s |
| 154 | + |
| 155 | + client.instance_variable_set(:@state, :dirty) |
| 156 | + |
| 157 | + second_socket_id = client.get("#{server.endpoint}/socket/2").body.to_s |
| 158 | + |
| 159 | + expect(first_socket_id).to_not eq(second_socket_id) |
| 160 | + end |
| 161 | + end |
| 162 | + |
151 | 163 | context "when trying to read a stale body" do
|
152 | 164 | it "errors" do
|
153 | 165 | client.get("#{server.endpoint}/not-found")
|
|
169 | 181 |
|
170 | 182 | context "with a socket issue" do
|
171 | 183 | it "transparently reopens" do
|
172 |
| - first_socket = client.get("#{server.endpoint}/socket").body.to_s |
173 |
| - expect(first_socket).to_not eq("") |
| 184 | + first_socket_id = client.get("#{server.endpoint}/socket").body.to_s |
| 185 | + expect(first_socket_id).to_not eq("") |
174 | 186 | # Kill off the sockets we used
|
175 | 187 | # rubocop:disable Style/RescueModifier
|
176 | 188 | DummyServer::Servlet.sockets.each do |socket|
|
|
183 | 195 | expect { client.get("#{server.endpoint}/socket").body.to_s }.to raise_error(IOError)
|
184 | 196 |
|
185 | 197 | # Should succeed since we create a new socket
|
186 |
| - second_socket = client.get("#{server.endpoint}/socket").body.to_s |
187 |
| - expect(second_socket).to_not eq(first_socket) |
| 198 | + second_socket_id = client.get("#{server.endpoint}/socket").body.to_s |
| 199 | + expect(second_socket_id).to_not eq(first_socket_id) |
188 | 200 | end
|
189 | 201 | end
|
190 | 202 |
|
|
0 commit comments