ae_network_connection_exception 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +30 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/Appraisals +11 -0
- data/Gemfile +5 -0
- data/Rakefile +17 -4
- data/gemfiles/ruby_2.3.3.gemfile +11 -0
- data/gemfiles/ruby_2.5.3.gemfile +11 -0
- data/lib/ae_network_connection_exception.rb +20 -13
- data/lib/ae_network_connection_exception/version.rb +1 -1
- data/test/test_helper.rb +28 -0
- data/test/unit/ae_network_connection_exception_test.rb +13 -35
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5b7cafe89fcbcdaf9925c573d2634a2bb132c1e455410a58eb37aec03ee2f08d
|
4
|
+
data.tar.gz: f78429a43ab640d0ebb3c957b35a111811fa6e34a715904bcf9881b06b4a093e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a571e1b3cc34c30bde269b5a3fcf756e2cd74eeef8d1399b6cc76b22404932d2a87a5988a72c5e20d6f2d7a1c07a02f6018bd5fadc02dfb0387034b7e4456175
|
7
|
+
data.tar.gz: 7b5cab2ccc00495417184b0dbbd7c3a42fd639d8051584273daef29e37f581bfa3004156b36483e6492cb89c9063911021d188559c0f81c44730e181f2a9e765
|
@@ -0,0 +1,30 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
working_directory: ~/repo
|
3
|
+
|
4
|
+
steps:
|
5
|
+
- checkout
|
6
|
+
- run: bundle install
|
7
|
+
- run: bundle exec appraisal install
|
8
|
+
- run: bundle exec appraisal rake test
|
9
|
+
|
10
|
+
version: 2
|
11
|
+
jobs:
|
12
|
+
test-ruby-2.3.3:
|
13
|
+
<<: *defaults
|
14
|
+
docker:
|
15
|
+
- image: circleci/ruby:2.3.3
|
16
|
+
|
17
|
+
test-ruby-2.5.3:
|
18
|
+
<<: *defaults
|
19
|
+
docker:
|
20
|
+
- image: circleci/ruby:2.5.3-stretch
|
21
|
+
|
22
|
+
workflows:
|
23
|
+
version: 2
|
24
|
+
rc:
|
25
|
+
jobs:
|
26
|
+
- test-ruby-2.3.3:
|
27
|
+
context: appfolio_test_context
|
28
|
+
- test-ruby-2.5.3:
|
29
|
+
context: appfolio_test_context
|
30
|
+
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.3
|
data/Appraisals
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,11 +1,24 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'af_gems/gem_tasks'
|
12
|
+
require 'af_gems/appraisal'
|
4
13
|
|
5
|
-
Rake::TestTask.new do |test|
|
14
|
+
Rake::TestTask.new(:test) do |test|
|
6
15
|
test.libs << 'lib' << 'test'
|
7
16
|
test.pattern = 'test/unit/**/*_test.rb'
|
8
17
|
test.verbose = true
|
9
18
|
end
|
10
19
|
|
20
|
+
task :default => :test
|
11
21
|
|
22
|
+
namespace :test do
|
23
|
+
AfGems::RubyAppraisalTask.new(:all, [ 'ruby-2.3.3', 'ruby-2.5.3' ])
|
24
|
+
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
require "ae_network_connection_exception/version"
|
2
|
+
require "net/http"
|
2
3
|
require "socket"
|
3
4
|
|
4
5
|
module AeNetworkConnectionException
|
5
|
-
|
6
6
|
class ConnectionNotEstablished < StandardError
|
7
7
|
end
|
8
8
|
|
9
|
+
OTHER_EXCEPTIONS = []
|
10
|
+
if defined?(RestClient::Exceptions::OpenTimeout)
|
11
|
+
puts "here"
|
12
|
+
OTHER_EXCEPTIONS << RestClient::Exceptions::OpenTimeout
|
13
|
+
end
|
14
|
+
OTHER_EXCEPTIONS.freeze
|
15
|
+
|
9
16
|
class << self
|
10
17
|
def try
|
11
18
|
yield
|
12
|
-
rescue SocketError, Net::OpenTimeout => e
|
19
|
+
rescue SocketError, Net::OpenTimeout, *OTHER_EXCEPTIONS => e
|
13
20
|
# SocketError happens when we fail to connect to a socket. Common problems here are DNS resolution (i.e. getaddrinfo)
|
14
21
|
# Net::OpenTimeout happens when we are unable to establish an HTTP connection before the open_timeout
|
15
22
|
|
@@ -25,25 +32,25 @@ module AeNetworkConnectionException
|
|
25
32
|
raise_if_exception_message_matches(e, /connect\(2\)/)
|
26
33
|
rescue Errno::ECONNRESET => e
|
27
34
|
# Errno::ECONNRESET happens when the connection is reset. This can happen during ssl negotiation
|
28
|
-
|
35
|
+
|
29
36
|
raise_if_exception_message_matches(e, /SSL_connect/)
|
30
37
|
end
|
31
|
-
|
38
|
+
|
32
39
|
# An array of examples for all the exceptions that we will catch
|
33
40
|
def exception_signatures
|
34
41
|
[
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
SocketError.new('getaddrinfo: Name or service not known'),
|
43
|
+
Errno::ECONNREFUSED.new('Connection refused - connect(2) for "example.com" port 443'),
|
44
|
+
Errno::ETIMEDOUT.new('Connection timed out - connect(2) for "example.com" port 443'),
|
45
|
+
Net::OpenTimeout.new('message'),
|
46
|
+
Errno::ECONNRESET.new('Connection reset by peer - SSL_connect', Errno::ECONNREFUSED.new('Connection refused - connect(2) for "example.com" port 443')),
|
47
|
+
Errno::EHOSTUNREACH.new('No route to host - connect(2) for "example.com" port 443'),
|
48
|
+
Errno::ENETUNREACH.new('Network is unreachable - connect(2) for "example.com" port 443')
|
42
49
|
]
|
43
50
|
end
|
44
|
-
|
51
|
+
|
45
52
|
private
|
46
|
-
|
53
|
+
|
47
54
|
def raise_if_exception_message_matches(exception, pattern)
|
48
55
|
if exception.message =~ pattern
|
49
56
|
raise ConnectionNotEstablished
|
data/test/test_helper.rb
CHANGED
@@ -2,3 +2,31 @@ require 'rubygems'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
require 'ae_network_connection_exception'
|
4
4
|
|
5
|
+
private
|
6
|
+
|
7
|
+
class Minitest::Test
|
8
|
+
def assert_connection_not_established_thrown_for(exception)
|
9
|
+
e = return_raised_error do
|
10
|
+
AeNetworkConnectionException.try do
|
11
|
+
raise exception
|
12
|
+
end
|
13
|
+
end
|
14
|
+
assert_equal AeNetworkConnectionException::ConnectionNotEstablished, e.class
|
15
|
+
assert_equal exception, e.cause
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_connection_not_established_not_thrown_for(exception)
|
19
|
+
e = return_raised_error do
|
20
|
+
AeNetworkConnectionException.try do
|
21
|
+
raise exception
|
22
|
+
end
|
23
|
+
end
|
24
|
+
assert_equal exception, e
|
25
|
+
end
|
26
|
+
|
27
|
+
def return_raised_error
|
28
|
+
yield
|
29
|
+
rescue => e
|
30
|
+
return e
|
31
|
+
end
|
32
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rest-client'
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
module AeNetworkConnectionException
|
@@ -5,10 +6,10 @@ module AeNetworkConnectionException
|
|
5
6
|
def test_connection_not_established_exception
|
6
7
|
# Exception Causes are standard with ruby 2.1
|
7
8
|
# http://devblog.avdi.org/2013/12/25/exception-causes-in-ruby-2-1
|
8
|
-
|
9
|
+
|
9
10
|
parent_exception = AeNetworkConnectionException::ConnectionNotEstablished.new('Parent Message')
|
10
11
|
|
11
|
-
|
12
|
+
assert_nil parent_exception.cause
|
12
13
|
assert_equal 'Parent Message', parent_exception.message
|
13
14
|
|
14
15
|
begin
|
@@ -36,16 +37,20 @@ module AeNetworkConnectionException
|
|
36
37
|
end
|
37
38
|
assert_equal exception, e
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
def test_ae_network_connection_exception_try__raises_connection_not_establised_exception
|
41
42
|
AeNetworkConnectionException.exception_signatures.each do |e|
|
42
43
|
assert_connection_not_established_thrown_for(e)
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
assert_connection_not_established_not_thrown_for(Errno::ECONNRESET.new('Connection timed out - connect(2) for "example.com" port 443'))
|
46
47
|
assert_connection_not_established_not_thrown_for(Errno::ETIMEDOUT.new('Connection timed out - recvfrom(2) for "example.com" port 443'))
|
47
48
|
end
|
48
|
-
|
49
|
+
|
50
|
+
def test_ae_network_connection_exception_try__raises_connection_not_establised_exception_for_rest_client_open_timeout
|
51
|
+
assert_connection_not_established_thrown_for(RestClient::Exceptions::OpenTimeout.new)
|
52
|
+
end
|
53
|
+
|
49
54
|
def test_exception_signatures
|
50
55
|
expected_signatures = [
|
51
56
|
SocketError.new('getaddrinfo: Name or service not known'),
|
@@ -56,39 +61,12 @@ module AeNetworkConnectionException
|
|
56
61
|
Errno::EHOSTUNREACH.new('No route to host - connect(2) for "example.com" port 443'),
|
57
62
|
Errno::ENETUNREACH.new('Network is unreachable - connect(2) for "example.com" port 443')
|
58
63
|
]
|
59
|
-
|
64
|
+
|
60
65
|
assert_equal expected_signatures.size, AeNetworkConnectionException.exception_signatures.size
|
61
|
-
|
62
|
-
expected_signatures.each do |e|
|
63
|
-
assert_includes AeNetworkConnectionException.exception_signatures, e
|
64
|
-
end
|
65
|
-
end
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
def assert_connection_not_established_thrown_for(exception)
|
70
|
-
e = return_raised_error do
|
71
|
-
AeNetworkConnectionException.try do
|
72
|
-
raise exception
|
73
|
-
end
|
74
|
-
end
|
75
|
-
assert_equal AeNetworkConnectionException::ConnectionNotEstablished, e.class
|
76
|
-
assert_equal exception, e.cause
|
77
|
-
end
|
78
|
-
|
79
|
-
def assert_connection_not_established_not_thrown_for(exception)
|
80
|
-
e = return_raised_error do
|
81
|
-
AeNetworkConnectionException.try do
|
82
|
-
raise exception
|
83
|
-
end
|
67
|
+
expected_signatures.each do |e|
|
68
|
+
assert_includes AeNetworkConnectionException.exception_signatures, e
|
84
69
|
end
|
85
|
-
assert_equal exception, e
|
86
|
-
end
|
87
|
-
|
88
|
-
def return_raised_error
|
89
|
-
yield
|
90
|
-
rescue => e
|
91
|
-
return e
|
92
70
|
end
|
93
71
|
end
|
94
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_network_connection_exception
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Boyd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,12 +46,17 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- ".circleci/config.yml"
|
49
50
|
- ".gitignore"
|
51
|
+
- ".ruby-version"
|
52
|
+
- Appraisals
|
50
53
|
- Gemfile
|
51
54
|
- LICENSE.txt
|
52
55
|
- README.md
|
53
56
|
- Rakefile
|
54
57
|
- ae_network_connection_exception.gemspec
|
58
|
+
- gemfiles/ruby_2.3.3.gemfile
|
59
|
+
- gemfiles/ruby_2.5.3.gemfile
|
55
60
|
- lib/ae_network_connection_exception.rb
|
56
61
|
- lib/ae_network_connection_exception/version.rb
|
57
62
|
- test/test_helper.rb
|
@@ -75,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
80
|
- !ruby/object:Gem::Version
|
76
81
|
version: '0'
|
77
82
|
requirements: []
|
78
|
-
|
79
|
-
rubygems_version: 2.4.8
|
83
|
+
rubygems_version: 3.0.6
|
80
84
|
signing_key:
|
81
85
|
specification_version: 4
|
82
86
|
summary: Provides sane exceptions for network failures
|