-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for different timeout options to all adapters
- Loading branch information
Alexey Chernenkov
committed
Aug 27, 2018
1 parent
885e373
commit 5d83dc9
Showing
9 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "spec_helper" | ||
require "httpi/adapter/excon" | ||
require "httpi/request" | ||
|
||
begin | ||
HTTPI::Adapter.load_adapter(:excon) | ||
|
||
describe HTTPI::Adapter::Excon do | ||
let(:adapter) { HTTPI::Adapter::Excon.new(request) } | ||
let(:request) { HTTPI::Request.new("http://example.com") } | ||
|
||
describe "settings" do | ||
describe "connect_timeout, read_timeout, write_timeout" do | ||
it "are passed as connection options" do | ||
request.open_timeout = 30 | ||
request.read_timeout = 40 | ||
request.write_timeout = 50 | ||
|
||
expect(adapter.client.data).to include( | ||
connect_timeout: 30, | ||
read_timeout: 40, | ||
write_timeout: 50 | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "spec_helper" | ||
require "httpi/adapter/http" | ||
require "httpi/request" | ||
|
||
begin | ||
HTTPI::Adapter.load_adapter(:http) | ||
|
||
describe HTTPI::Adapter::HTTP do | ||
let(:adapter) { HTTPI::Adapter::HTTP.new(request) } | ||
let(:request) { HTTPI::Request.new("http://example.com") } | ||
|
||
describe "settings" do | ||
describe "connect_timeout, read_timeout, write_timeout" do | ||
it "are being set on the client" do | ||
request.open_timeout = 30 | ||
request.read_timeout = 40 | ||
request.write_timeout = 50 | ||
|
||
expect(adapter.client.default_options.timeout_options).to eq( | ||
connect_timeout: 30, | ||
read_timeout: 40, | ||
write_timeout: 50 | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "spec_helper" | ||
require "httpi/adapter/net_http_persistent" | ||
require "httpi/request" | ||
|
||
begin | ||
HTTPI::Adapter.load_adapter(:net_http_persistent) | ||
|
||
describe HTTPI::Adapter::NetHTTPPersistent do | ||
let(:adapter) { HTTPI::Adapter::NetHTTPPersistent.new(request) } | ||
let(:request) { HTTPI::Request.new("http://example.com") } | ||
|
||
let(:response) { | ||
Object.new.tap do |r| | ||
r.stubs(:code).returns(200) | ||
r.stubs(:body).returns("abc") | ||
r.stubs(:to_hash).returns({"Content-Length" => "3"}) | ||
end | ||
} | ||
|
||
before do | ||
Net::HTTP::Persistent.any_instance.stubs(:start).returns(response) | ||
end | ||
|
||
describe "settings" do | ||
describe "open_timeout, read_timeout" do | ||
it "are being set on the client" do | ||
request.open_timeout = 30 | ||
request.read_timeout = 40 | ||
|
||
adapter.client.expects(:open_timeout=).with(30) | ||
adapter.client.expects(:read_timeout=).with(40) | ||
|
||
adapter.request(:get) | ||
end | ||
end | ||
|
||
describe "write_timeout" do | ||
it "is not supported" do | ||
request.write_timeout = 50 | ||
expect { adapter.request(:get) } | ||
.to raise_error(HTTPI::NotSupportedError, /write_timeout/) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "spec_helper" | ||
require "httpi/adapter/net_http" | ||
require "httpi/request" | ||
|
||
begin | ||
HTTPI::Adapter.load_adapter(:net_http) | ||
|
||
describe HTTPI::Adapter::NetHTTP do | ||
let(:adapter) { HTTPI::Adapter::NetHTTP.new(request) } | ||
let(:request) { HTTPI::Request.new("http://example.com") } | ||
|
||
let(:response) { | ||
Object.new.tap do |r| | ||
r.stubs(:code).returns(200) | ||
r.stubs(:body).returns("abc") | ||
r.stubs(:to_hash).returns({"Content-Length" => "3"}) | ||
end | ||
} | ||
|
||
before do | ||
Net::HTTP.any_instance.stubs(:start).returns(response) | ||
end | ||
|
||
describe "settings" do | ||
describe "open_timeout, read_timeout" do | ||
it "are being set on the client" do | ||
request.open_timeout = 30 | ||
request.read_timeout = 40 | ||
|
||
adapter.client.expects(:open_timeout=).with(30) | ||
adapter.client.expects(:read_timeout=).with(40) | ||
|
||
adapter.request(:get) | ||
end | ||
end | ||
|
||
describe "write_timeout" do | ||
if Net::HTTP.method_defined?(:write_timeout=) | ||
it "is being set on the client" do | ||
request.write_timeout = 50 | ||
adapter.client.expects(:write_timeout=).with(50) | ||
adapter.request(:get) | ||
end | ||
else | ||
it "can not be set on the client" do | ||
request.write_timeout = 50 | ||
expect { adapter.request(:get) } | ||
.to raise_error(HTTPI::NotSupportedError, /write_timeout/) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters