|
312 | 312 | let(:answer) { { "foo" => "bar" } } |
313 | 313 | let(:query) { "my query here" } |
314 | 314 |
|
| 315 | + it "reconnects and retries after the connection times out" do |
| 316 | + response = instance_double(Net::HTTPOK, code: "200", body: JSON.generate(answer)) |
| 317 | + timed_out_http = Net::HTTP.new("github.fake", 443) |
| 318 | + replacement_http = Net::HTTP.new("github.fake", 443) |
| 319 | + |
| 320 | + expect(Net::HTTP).to receive(:new). |
| 321 | + with("github.fake", 443). |
| 322 | + twice. |
| 323 | + and_return(timed_out_http, replacement_http) |
| 324 | + expect(timed_out_http).to receive(:use_ssl=).with(true) |
| 325 | + expect(timed_out_http).to receive(:start) |
| 326 | + expect(timed_out_http).to receive(:request). |
| 327 | + and_raise(Net::ReadTimeout, "execution expired") |
| 328 | + expect(timed_out_http).to receive(:started?).and_return(true) |
| 329 | + expect(timed_out_http).to receive(:finish) |
| 330 | + expect(replacement_http).to receive(:use_ssl=).with(true) |
| 331 | + expect(replacement_http).to receive(:start) |
| 332 | + expect(replacement_http).to receive(:request).and_return(response) |
| 333 | + expect_any_instance_of(Object).to receive(:sleep).with(1).once |
| 334 | + expect(logger).to receive(:error). |
| 335 | + with("Caught Net::ReadTimeout POSTing to https://github.fake/api/v3/graphql: Net::ReadTimeout with \"execution expired\"") |
| 336 | + expect(logger).to receive(:warn). |
| 337 | + with("GraphQL failed on try 1 of 3. Will retry.") |
| 338 | + |
| 339 | + expect(subject.send(:graphql_http_post, query)).to eq(code: 200, data: answer) |
| 340 | + end |
| 341 | + |
315 | 342 | it "returns immediately for success" do |
316 | 343 | expect(subject).to receive(:graphql_http_post_real).with(query).and_return(code: 200, data: answer) |
317 | 344 | expect_any_instance_of(Object).not_to receive(:sleep) |
|
0 commit comments