From 58ece864c421c1f49682d9a9977b69d7255ece01 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Tue, 29 Sep 2015 06:34:25 -0700 Subject: [PATCH] Fixed global timeout state persistence --- lib/http/timeout/global.rb | 4 ++++ spec/lib/http/client_spec.rb | 7 +++++-- spec/support/http_handling_shared.rb | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/http/timeout/global.rb b/lib/http/timeout/global.rb index 3017cacd..0b0fb612 100644 --- a/lib/http/timeout/global.rb +++ b/lib/http/timeout/global.rb @@ -9,7 +9,11 @@ class Global < PerOperation def initialize(*args) super + reset_counter + end + # To future me: Don't remove this again, past you was smarter. + def reset_counter @time_left = connect_timeout + read_timeout + write_timeout @total_timeout = time_left end diff --git a/spec/lib/http/client_spec.rb b/spec/lib/http/client_spec.rb index 23e13cdf..4ea78294 100644 --- a/spec/lib/http/client_spec.rb +++ b/spec/lib/http/client_spec.rb @@ -190,16 +190,19 @@ def simple_response(body, status = 200) end include_context "HTTP handling" do + let(:extra_options) { {} } let(:options) { {} } let(:server) { dummy } - let(:client) { described_class.new(options) } + let(:client) { described_class.new(options.merge(extra_options)) } end describe "working with SSL" do run_server(:dummy_ssl) { DummyServer.new(:ssl => true) } + let(:extra_options) { {} } + let(:client) do - described_class.new options.merge :ssl_context => SSLHelper.client_context + described_class.new options.merge(:ssl_context => SSLHelper.client_context).merge(extra_options) end include_context "HTTP handling" do diff --git a/spec/support/http_handling_shared.rb b/spec/support/http_handling_shared.rb index 432f8d53..3a67a4cd 100644 --- a/spec/support/http_handling_shared.rb +++ b/spec/support/http_handling_shared.rb @@ -88,9 +88,9 @@ end context "it resets state when reusing connections" do - let(:options) { {:persistent => server.endpoint} } + let(:extra_options) { {:persistent => server.endpoint} } - let(:read_timeout) { 3 } + let(:read_timeout) { 2.5 } it "does not timeout" do client.get("#{server.endpoint}/sleep").body.to_s