zold 0.14.41 → 0.14.42

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: 6b4683993fc4c2115b2cf6cf69ea4bc157eb05c2
4
- data.tar.gz: 83a3040d404d3b71c2af331bf4085950bfa17fd3
3
+ metadata.gz: 04ead080c429afa3f286620b291fc6e9de095179
4
+ data.tar.gz: ee0952e4a5aa6d58ff53a67eecb72f334b14b756
5
5
  SHA512:
6
- metadata.gz: d28d9c5c4170478c60793e1f7bcab3a50af9cc5fd06b33f78500bd0c8c862010c738a2ca2c00bcf42a20a35512a8955f0e99c8ecb6b55cc6d2016f091ee5997b
7
- data.tar.gz: d078e2ec1833d55e2087926e5eac1ac50fc2c199e93f8326a3e8b410f1ba969381d89416d5ca2b09cfd46d2a99ffe527a628e1aa0e1a985aa0702ffb8cba3de1
6
+ metadata.gz: 7a2ce8dcec67d5b1187012418cf3282c8afd8fac2fa86f25f0278867513331c046b429fa5c1fc691d0b8208c1d3841586e0f59ccbcf32ae8b1ffda13073cada1
7
+ data.tar.gz: 8193aa27712e777cf67ebcc688d86f7cd22fba0910e8857d42fc531541ad8b28d9b48f69e3f93547501a174616e98aecaec0cad89c99a4d1b055e8e037f4b88b
data/lib/zold/http.rb CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'rainbow'
24
24
  require 'uri'
25
+ require 'timeout'
25
26
  require 'net/http'
26
27
  require_relative 'backtrace'
27
28
  require_relative 'version'
@@ -54,10 +55,10 @@ module Zold
54
55
  PROTOCOL_HEADER = 'X-Zold-Protocol'
55
56
 
56
57
  # Read timeout in seconds
57
- READ_TIMEOUT = 32
58
+ READ_TIMEOUT = 4
58
59
 
59
60
  # Connect timeout in seconds
60
- CONNECT_TIMEOUT = 8
61
+ CONNECT_TIMEOUT = 4
61
62
 
62
63
  # @todo #98:30m/DEV The following two statements are seen as issues by rubocop
63
64
  # raising a Lint/AmbiguousBlockAssociation offense. It is somthing
@@ -76,7 +77,9 @@ module Zold
76
77
  http.open_timeout = Http::CONNECT_TIMEOUT
77
78
  path = uri.path
78
79
  path += '?' + uri.query if uri.query
79
- http.request_get(path, headers)
80
+ Timeout.timeout(Http::READ_TIMEOUT + Http::CONNECT_TIMEOUT) do
81
+ http.request_get(path, headers)
82
+ end
80
83
  rescue StandardError => e
81
84
  Error.new(e)
82
85
  end
@@ -88,13 +91,15 @@ module Zold
88
91
  http.open_timeout = Http::CONNECT_TIMEOUT
89
92
  path = uri.path
90
93
  path += '?' + uri.query if uri.query
91
- http.request_put(
92
- path, body,
93
- headers.merge(
94
- 'Content-Type': 'text/plain',
95
- 'Content-Length': body.length.to_s
94
+ Timeout.timeout(Http::READ_TIMEOUT + Http::CONNECT_TIMEOUT) do
95
+ http.request_put(
96
+ path, body,
97
+ headers.merge(
98
+ 'Content-Type': 'text/plain',
99
+ 'Content-Length': body.length.to_s
100
+ )
96
101
  )
97
- )
102
+ end
98
103
  rescue StandardError => e
99
104
  Error.new(e)
100
105
  end
data/lib/zold/version.rb CHANGED
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.14.41'
28
+ VERSION = '0.14.42'
29
29
  PROTOCOL = 2
30
30
  end
data/test/test_http.rb CHANGED
@@ -25,6 +25,7 @@ require 'tmpdir'
25
25
  require 'uri'
26
26
  require 'webmock/minitest'
27
27
  require_relative '../lib/zold/http'
28
+ require_relative '../lib/zold/score'
28
29
 
29
30
  # Http test.
30
31
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -68,6 +69,15 @@ class TestHttp < Minitest::Test
68
69
  assert_equal('200', res.code)
69
70
  end
70
71
 
72
+ def test_terminates_on_timeout
73
+ stub_request(:get, 'http://the-fake-host-99/').to_return do
74
+ sleep 100
75
+ { body: 'This should never be returned!' }
76
+ end
77
+ res = Zold::Http.new(uri: 'http://the-fake-host-99/', score: nil).get
78
+ assert_equal('599', res.code)
79
+ end
80
+
71
81
  def test_sends_valid_version_header
72
82
  stub_request(:get, 'http://some-host-3/')
73
83
  .with(headers: { 'X-Zold-Version' => Zold::VERSION })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.41
4
+ version: 0.14.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-04 00:00:00.000000000 Z
11
+ date: 2018-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cachy