Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 8a92d26

Browse files
author
Miguel Angel
committed
Add support for changing the timeout
1 parent b5d6069 commit 8a92d26

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

lib/code_climate/test_reporter/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def http_client(uri)
8080
http.ca_file = File.expand_path('../../../../config/cacert.pem', __FILE__)
8181
http.verify_depth = 5
8282
end
83-
http.open_timeout = DEFAULT_TIMEOUT # in seconds
84-
http.read_timeout = DEFAULT_TIMEOUT # in seconds
83+
http.open_timeout = CodeClimate::TestReporter.configuration.timeout
84+
http.read_timeout = CodeClimate::TestReporter.configuration.timeout
8585
end
8686
end
8787

lib/code_climate/test_reporter/configuration.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def self.configuration
2121
class Configuration
2222
attr_accessor :branch, :path_prefix, :gzip_request, :git_dir
2323

24-
attr_writer :logger, :profile
24+
attr_writer :logger, :profile, :timeout
2525

2626
def initialize
2727
@gzip_request = true
@@ -39,6 +39,10 @@ def skip_token
3939
@skip_token ||= "nocov"
4040
end
4141

42+
def timeout
43+
@timeout ||= Client::DEFAULT_TIMEOUT
44+
end
45+
4246
private
4347

4448
def default_logger

spec/lib/client_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'spec_helper'
2+
3+
module CodeClimate::TestReporter
4+
describe Client do
5+
it 'sets the http timeout per configuration' do
6+
new_timeout = 969
7+
CodeClimate::TestReporter.configure do |config|
8+
config.timeout = new_timeout
9+
end
10+
11+
response = double(:response, code: 200)
12+
net_http = double(:net_http, request: response)
13+
allow(Net::HTTP).to receive(:new).
14+
and_return(net_http)
15+
16+
expect(net_http).to receive(:open_timeout=).
17+
with(new_timeout)
18+
expect(net_http).to receive(:read_timeout=).
19+
with(new_timeout)
20+
21+
Client.new.post_results("")
22+
end
23+
end
24+
end

spec/lib/configuration_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module CodeClimate::TestReporter
1515
expect(CodeClimate::TestReporter.configuration.profile).to eq('test_frameworks')
1616
expect(CodeClimate::TestReporter.configuration.path_prefix).to be_nil
1717
expect(CodeClimate::TestReporter.configuration.skip_token).to eq('nocov')
18+
expect(CodeClimate::TestReporter.configuration.timeout).to eq(Client::DEFAULT_TIMEOUT)
1819
end
1920
end
2021

@@ -60,7 +61,14 @@ module CodeClimate::TestReporter
6061
CodeClimate::TestReporter.configure do |config|
6162
config.path_prefix = nil
6263
end
64+
end
65+
66+
it 'stores timeout' do
67+
CodeClimate::TestReporter.configure do |config|
68+
config.timeout = 666
69+
end
6370

71+
expect(CodeClimate::TestReporter.configuration.timeout).to eq(666)
6472
end
6573
end
6674
end

0 commit comments

Comments
 (0)