pebblebed 0.3.22 → 0.3.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d6cc9e91f2cc09da6e335cceeb464b2587e13f6
4
- data.tar.gz: 6bdf45e966352b2b75fb9f86c665a578e439e209
3
+ metadata.gz: 08c5433c73871b5f51b25a26056ce1fd53728451
4
+ data.tar.gz: b0f9a69395146a1809d9c0384a1de420cc797f05
5
5
  SHA512:
6
- metadata.gz: 9b96f0a8865ddde136b66bc93be02e27cbaaf60b88ddfe9548dfbaf35a19c056387e84b53106897139e0f6d343905b981d0ac4ff47fd41d4783178bbc3f6caaa
7
- data.tar.gz: 0d1d0a8376de9876073f8fab97deac8b9ce82959f7a5aae1a42f2d02d924cfddd45ff242cbb6995207387ff82f97e0785818003272fa8cc6a282c96b9ba79156
6
+ metadata.gz: 82ce8666be3e634e26e0bec2e07e88d56feca7603bae7029adb782b57c1b6d4ef534a391d81dfd62ba42f400b6d199f2ac9d25e89b1e26d4adc562f9fcaabdd6
7
+ data.tar.gz: 29c042e7f0466976ae79e15401d617e909b7b08da5578283fd9187cefe131417a1b89d4739ef5abbb2f1cb209846463d3d9177976bb141991b3172fcf377f89f
@@ -9,6 +9,7 @@ require 'pathbuilder'
9
9
  require 'active_support'
10
10
 
11
11
  module Pebblebed
12
+
12
13
  class HttpError < StandardError
13
14
  attr_reader :status, :message, :response
14
15
 
@@ -31,12 +32,18 @@ module Pebblebed
31
32
  end
32
33
  end
33
34
 
34
- class HttpNotFoundError < HttpError
35
-
36
- end
35
+ class HttpNotFoundError < HttpError; end
37
36
 
38
37
  module Http
39
38
 
39
+ DEFAULT_CONNECT_TIMEOUT = 30
40
+ DEFAULT_REQUEST_TIMEOUT = nil
41
+ DEFAULT_READ_TIMEOUT = 30
42
+
43
+ class << self
44
+ attr_accessor :connect_timeout, :request_timeout, :read_timeout
45
+ end
46
+
40
47
  class Response
41
48
  def initialize(easy)
42
49
  @body = easy.body_str
@@ -173,16 +180,16 @@ module Pebblebed
173
180
  end
174
181
 
175
182
  def self.with_easy(&block)
176
- easy = Thread.current[:pebblebed_curb_easy] ||= Curl::Easy.new
177
- begin
178
- easy.reset
179
- rescue RuntimeError => e
180
- # This can happen if previous streaming isn't finished
181
- raise unless e.to_s =~ /^Cannot close an active curl handle within a callback/
182
- easy.close rescue nil
183
- easy = Thread.current[:pebblebed_curb_easy] = Curl::Easy.new
184
- end
185
- yield easy
183
+ yield new_easy
184
+ end
185
+
186
+ def self.new_easy
187
+ easy = Curl::Easy.new
188
+ easy.connect_timeout = connect_timeout || DEFAULT_CONNECT_TIMEOUT
189
+ easy.timeout = request_timeout || DEFAULT_REQUEST_TIMEOUT
190
+ easy.low_speed_time = read_timeout || DEFAULT_READ_TIMEOUT
191
+ easy.low_speed_limit = 1
192
+ easy
186
193
  end
187
194
 
188
195
  def self.url_with_params(url, params)
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.3.22"
2
+ VERSION = "0.3.23"
3
3
  end
data/spec/http_spec.rb CHANGED
@@ -21,6 +21,10 @@ describe Pebblebed::Http do
21
21
  end
22
22
 
23
23
  before :all do
24
+ Pebblebed::Http.connect_timeout = nil
25
+ Pebblebed::Http.request_timeout = nil
26
+ Pebblebed::Http.read_timeout = nil
27
+
24
28
  # Starts the mock pebble at localhost:8666/api/mock/v1
25
29
  mock_pebble.start
26
30
  end
@@ -102,4 +106,25 @@ describe Pebblebed::Http do
102
106
  end
103
107
  end
104
108
 
109
+ it "enforces request timeout" do
110
+ Pebblebed::Http.request_timeout = 1
111
+ expect {
112
+ Pebblebed::Http.get(pebble_url, {slow: '2'})
113
+ }.to raise_error(Curl::Err::TimeoutError)
114
+ expect {
115
+ Pebblebed::Http.get(pebble_url, {slow: '0.5'})
116
+ }.not_to raise_error
117
+ end
118
+
119
+ it "enforces read timeout" do
120
+ Pebblebed::Http.request_timeout = 1000
121
+ Pebblebed::Http.read_timeout = 1
122
+ expect {
123
+ Pebblebed::Http.get(pebble_url, {slow: '30'})
124
+ }.to raise_error(Curl::Err::TimeoutError)
125
+ expect {
126
+ Pebblebed::Http.get(pebble_url, {slow: '0.5'})
127
+ }.not_to raise_error
128
+ end
129
+
105
130
  end
data/spec/mock_pebble.rb CHANGED
@@ -41,6 +41,10 @@ class MockPebble
41
41
  end
42
42
 
43
43
  def do_stuff_with(request)
44
+ if request.request_uri.to_s =~ /slow=(\d+)/
45
+ delay = $1.to_i
46
+ sleep(delay)
47
+ end
44
48
  return 200, "application/json", request.meta_vars.merge("BODY" => request.body).to_json
45
49
  end
46
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebblebed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.22
4
+ version: 0.3.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-24 00:00:00.000000000 Z
12
+ date: 2017-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec