zold 0.14.41 → 0.14.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/zold/http.rb +14 -9
- data/lib/zold/version.rb +1 -1
- data/test/test_http.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04ead080c429afa3f286620b291fc6e9de095179
|
4
|
+
data.tar.gz: ee0952e4a5aa6d58ff53a67eecb72f334b14b756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
58
|
+
READ_TIMEOUT = 4
|
58
59
|
|
59
60
|
# Connect timeout in seconds
|
60
|
-
CONNECT_TIMEOUT =
|
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
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
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.
|
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-
|
11
|
+
date: 2018-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cachy
|