Skip to content

Commit 3298437

Browse files
hosomCopilot
andcommitted
Test GraphQL recovery after connection timeout
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent be85a47 commit 3298437

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎spec/unit/entitlements/service/github_spec.rb‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,33 @@
312312
let(:answer) { { "foo" => "bar" } }
313313
let(:query) { "my query here" }
314314

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+
315342
it "returns immediately for success" do
316343
expect(subject).to receive(:graphql_http_post_real).with(query).and_return(code: 200, data: answer)
317344
expect_any_instance_of(Object).not_to receive(:sleep)

0 commit comments

Comments
 (0)