Skip to content
Snippets Groups Projects
Commit 9ff0560e authored by capotej's avatar capotej
Browse files

accept various timeout settings via Connection

parent 74a8ad8c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -54,7 +54,7 @@ module Packagecloud
port = self.connection.port
token = self.credentials.token
 
@excon = Excon.new("#{scheme}://#{token}@#{host}:#{port}")
@excon = Excon.new("#{scheme}://#{token}@#{host}:#{port}", :connect_timeout => @connection.connect_timeout)
assert_valid_credentials
end
 
Loading
Loading
@@ -243,7 +243,8 @@ module Packagecloud
if body != nil
request_params.merge!({ :body => body })
end
@excon.request(request_params)
@excon.request(request_params.merge({:read_timeout => connection.read_timeout, :write_timeout => connection.write_timeout }))
end
 
# returns the parsed body of a successful result
Loading
Loading
module Packagecloud
class Connection
attr_reader :scheme, :host, :port
attr_reader :scheme, :host, :port, :connect_timeout, :read_timeout, :write_timeout
 
def initialize(scheme="https", host="packagecloud.io", port="443")
def initialize(scheme="https", host="packagecloud.io", port="443", options={})
@scheme = scheme
@host = host
@port = port
@connect_timeout = options[:connect_timeout] || 60
@read_timeout = options[:read_timeout] || 60
@write_timeout = options[:write_timeout] || 180
end
end
end
\ No newline at end of file
end
Loading
Loading
@@ -208,6 +208,27 @@ describe Packagecloud do
}.to raise_error(UnauthenticatedException)
end
 
context "timeouts" do
it "should have defaults" do
credentials = Credentials.new("joedamato", "test_token")
connection = Connection.new("http", "localhost", 8000)
client = Client.new(credentials, "test_client", connection)
expect(client.connection.read_timeout).to eql(60)
expect(client.connection.write_timeout).to eql(180)
expect(client.connection.connect_timeout).to eql(60)
end
it "should respect passed values" do
credentials = Credentials.new("joedamato", "test_token")
timeouts = { :connect_timeout => 10, :read_timeout => 80, :write_timeout => 280 }
connection = Connection.new("http", "localhost", 8000, timeouts)
client = Client.new(credentials, "test_client", connection)
expect(client.connection.read_timeout).to eql(80)
expect(client.connection.write_timeout).to eql(280)
expect(client.connection.connect_timeout).to eql(10)
end
end
describe "find_distribution_id" do
it "should find ubuntu/breezy" do
id = @client.find_distribution_id("ubuntu/breezy")
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment