|
157 | 157 |
|
158 | 158 | describe "exception caching" do |
159 | 159 | let(:unreachable_url) { "https://example.local" } |
| 160 | + let(:escaped_unreachable_url) { Regexp.escape(unreachable_url) } |
160 | 161 |
|
161 | 162 | before do |
162 | 163 | described_class.clear_cache! |
163 | | - allow(Excon).to receive(:get).with(/#{unreachable_url}/, anything).and_raise(error) |
164 | | - allow(Excon).to receive(:head).with(/#{unreachable_url}/, anything).and_raise(error) |
| 164 | + allow(Excon).to receive(:get).with(/#{escaped_unreachable_url}/, anything).and_raise(error) |
| 165 | + allow(Excon).to receive(:head).with(/#{escaped_unreachable_url}/, anything).and_raise(error) |
165 | 166 | end |
166 | 167 |
|
167 | 168 | describe "when Excon times out internally" do |
|
185 | 186 | end |
186 | 187 |
|
187 | 188 | describe "when Excon encounters a socket error" do |
188 | | - let(:error) { Excon::Error::Socket.new(EOFError.new) } |
| 189 | + context "with EOFError" do |
| 190 | + let(:error) { Excon::Error::Socket.new(EOFError.new) } |
189 | 191 |
|
190 | | - it "only attempts to reach it once via get and then plays back the first error" do |
191 | | - expect(Excon).to receive(:get).with(unreachable_url, anything).once |
| 192 | + it "does not cache get failures" do |
| 193 | + expect(Excon).to receive(:get).with(/#{escaped_unreachable_url}/, anything).exactly(3).times |
192 | 194 |
|
193 | | - expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
194 | | - expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
195 | | - expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
196 | | - end |
| 195 | + expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 196 | + expect { described_class.get(url: "#{unreachable_url}/foos") }.to raise_error(Excon::Error::Socket) |
| 197 | + expect { described_class.get(url: "#{unreachable_url}/foos/bars") }.to raise_error(Excon::Error::Socket) |
| 198 | + end |
197 | 199 |
|
198 | | - it "replays the first get error for the host on any request path" do |
199 | | - expect(Excon).to receive(:get).with(unreachable_url, anything).once |
| 200 | + it "does not cache head failures" do |
| 201 | + expect(Excon).to receive(:head).with(/#{escaped_unreachable_url}/, anything).exactly(3).times |
200 | 202 |
|
201 | | - expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
202 | | - expect { described_class.get(url: "#{unreachable_url}/foos") }.to raise_error(Excon::Error::Socket) |
203 | | - expect { described_class.get(url: "#{unreachable_url}/foos/bars") }.to raise_error(Excon::Error::Socket) |
| 203 | + expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 204 | + expect { described_class.head(url: "#{unreachable_url}/foos") }.to raise_error(Excon::Error::Socket) |
| 205 | + expect { described_class.head(url: "#{unreachable_url}/foos/bars") }.to raise_error(Excon::Error::Socket) |
| 206 | + end |
204 | 207 | end |
205 | 208 |
|
206 | | - it "only attempts to reach it once via head and then plays back the first error" do |
207 | | - expect(Excon).to receive(:head).with(unreachable_url, anything).once |
| 209 | + context "with non-EOF socket errors" do |
| 210 | + let(:error) { Excon::Error::Socket.new(SocketError.new("getaddrinfo failed")) } |
208 | 211 |
|
209 | | - expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
210 | | - expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
211 | | - expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
212 | | - end |
| 212 | + it "only attempts to reach it once via get and then plays back the first error" do |
| 213 | + expect(Excon).to receive(:get).with(unreachable_url, anything).once |
| 214 | + |
| 215 | + expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 216 | + expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 217 | + expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 218 | + end |
213 | 219 |
|
214 | | - it "replays the first head error for the host on any request path" do |
215 | | - expect(Excon).to receive(:head).with(unreachable_url, anything).once |
| 220 | + it "replays the first get error for the host on any request path" do |
| 221 | + expect(Excon).to receive(:get).with(unreachable_url, anything).once |
216 | 222 |
|
217 | | - expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
218 | | - expect { described_class.head(url: "#{unreachable_url}/foos") }.to raise_error(Excon::Error::Socket) |
219 | | - expect { described_class.head(url: "#{unreachable_url}/foos/bars") }.to raise_error(Excon::Error::Socket) |
| 223 | + expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 224 | + expect { described_class.get(url: "#{unreachable_url}/foos") }.to raise_error(Excon::Error::Socket) |
| 225 | + expect { described_class.get(url: "#{unreachable_url}/foos/bars") }.to raise_error(Excon::Error::Socket) |
| 226 | + end |
| 227 | + |
| 228 | + it "only attempts to reach it once via head and then plays back the first error" do |
| 229 | + expect(Excon).to receive(:head).with(unreachable_url, anything).once |
| 230 | + |
| 231 | + expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 232 | + expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 233 | + expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 234 | + end |
| 235 | + |
| 236 | + it "replays the first head error for the host on any request path" do |
| 237 | + expect(Excon).to receive(:head).with(unreachable_url, anything).once |
| 238 | + |
| 239 | + expect { described_class.head(url: unreachable_url) }.to raise_error(Excon::Error::Socket) |
| 240 | + expect { described_class.head(url: "#{unreachable_url}/foos") }.to raise_error(Excon::Error::Socket) |
| 241 | + expect { described_class.head(url: "#{unreachable_url}/foos/bars") }.to raise_error(Excon::Error::Socket) |
| 242 | + end |
220 | 243 | end |
221 | 244 | end |
222 | 245 |
|
|
228 | 251 | let(:error) { error_class.new(error_message) } |
229 | 252 |
|
230 | 253 | it "does not cache anything" do |
231 | | - expect(Excon).to receive(:get).with(/#{unreachable_url}/, anything) |
| 254 | + expect(Excon).to receive(:get).with(/#{escaped_unreachable_url}/, anything) |
232 | 255 |
|
233 | 256 | expect { described_class.get(url: unreachable_url) }.to raise_error(error_class) |
234 | 257 | expect { described_class.get(url: "#{unreachable_url}/foos") }.to raise_error(error_class) |
|
242 | 265 | let(:error) { Excon::Error.new("Boom!") } |
243 | 266 |
|
244 | 267 | it "does not cache anything" do |
245 | | - expect(Excon).to receive(:get).with(/#{unreachable_url}/, anything) |
| 268 | + expect(Excon).to receive(:get).with(/#{escaped_unreachable_url}/, anything) |
246 | 269 |
|
247 | 270 | expect { described_class.get(url: unreachable_url) }.to raise_error(Excon::Error) |
248 | 271 | expect { described_class.get(url: "#{unreachable_url}/foos") }.to raise_error(Excon::Error) |
|
0 commit comments