unobtainium 0.4.0 → 0.5.0

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: 97948bc83a14acdbe6c71e330e66e907d2a19fe7
4
- data.tar.gz: 33ad8b54a05cd91a90935896378bdba28d9f12cb
3
+ metadata.gz: b7101f0e169ee18822dea81ce744bf8b86bab64a
4
+ data.tar.gz: 500258b36f1090ec08f3c51c23f40818e555c394
5
5
  SHA512:
6
- metadata.gz: 63da85ce1551f33687e11cbb1d59577303907797e8c0cf1a935d692d9922cfb8cf8ace0f30bdd4badc5f97245cc5449127f734952865e3121bc0c58f60266987
7
- data.tar.gz: a737bd06d28b979976cd56ac4bd82ab7f918b21d32b6a84a036bb0b1706e9a6103580fa0acef97ce60533d161d5eb45fd77515df3c8e99e84438278b639954e8
6
+ metadata.gz: a372094b13fa1d4faaa78e5478aee58df00bafff7a6efd3b05ae8f7371d309128eb4c486c44d8ba4b9a7c36ec83b63d22d8a4d36176cd3608ec3fcd160e154c4
7
+ data.tar.gz: 5e5a94cf7577499a32af36fd6e0115b3fecd39d880ec3e97c1d11ae746274c5331e38a1daad919faa0904e497157c001d2b4491cd9bc2e94e5572ef4cfbf957a
data/.codeclimate.yml CHANGED
@@ -9,6 +9,7 @@ engines:
9
9
  - a8e2b4ccb258f16eda697c5f98e21823
10
10
  - 442a316695836b4f4693fe3786cd3396
11
11
  - 1c24bb5da72323796b645814cc006684
12
+ - 4ff1112a73f7be30ecefa7bd90fdbf5a
12
13
  config:
13
14
  languages:
14
15
  - ruby
data/.rubocop.yml CHANGED
@@ -27,6 +27,9 @@ Metrics/CyclomaticComplexity:
27
27
  Metrics/ClassLength:
28
28
  Max: 300
29
29
 
30
+ Metrics/ModuleLength:
31
+ Max: 300
32
+
30
33
  # Style
31
34
 
32
35
  Style/StringLiterals:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unobtainium (0.4.0)
4
+ unobtainium (0.5.0)
5
5
  sys-proctable (~> 1.0)
6
6
 
7
7
  GEM
@@ -37,7 +37,7 @@ GEM
37
37
  gherkin (3.2.0)
38
38
  json (1.8.3)
39
39
  mini_portile2 (2.0.0)
40
- multi_json (1.11.3)
40
+ multi_json (1.12.0)
41
41
  multi_test (0.1.2)
42
42
  nokogiri (1.6.7.2)
43
43
  mini_portile2 (~> 2.0.0.rc2)
data/README.md CHANGED
@@ -92,7 +92,7 @@ details.
92
92
  - [unobtainium-faraday](https://github.com/jfinkhaeuser/unobtainium-faraday) is
93
93
  a faraday-based driver for dealing with RESTish APIs.
94
94
  - [unobtainium-kramdown](https://github.com/jfinkhaeuser/unobtainium-kramdown) is
95
- a faraday-based driver for dealing with Markdown structured text.
95
+ an open-uri-based driver for dealing with Markdown structured text.
96
96
 
97
97
  # Credits
98
98
  This gem is inspired by [LapisLazuli](https://github.com/spriteCloud/lapis-lazuli),
data/Rakefile CHANGED
@@ -27,6 +27,8 @@ desc "Test all the things!"
27
27
  task :test do
28
28
  Rake::Task[:rubocop].invoke
29
29
  Rake::Task[:rspec].invoke
30
+ ENV['DRIVER'] = 'headless'
31
+ Rake::Task[:cuke].invoke
30
32
  end
31
33
 
32
34
  # Default is the test task
@@ -125,7 +125,14 @@ module Unobtainium
125
125
  timeout -= 1
126
126
  end
127
127
  if timeout <= 0
128
- raise "Timeout waiting to connect to PhantomJS!"
128
+ runner.kill
129
+ out = runner.stdout.read
130
+ err = runner.stderr.read
131
+ runner.reset
132
+
133
+ raise "Timeout waiting to connect to PhantomJS!\n"\
134
+ "STDOUT: #{out}\n"\
135
+ "STDERR: #{err}"
129
136
  end
130
137
 
131
138
  # Run Selenium against server
@@ -57,22 +57,18 @@ module Unobtainium
57
57
  end
58
58
 
59
59
  # Test a socket for each domain
60
- addr = Socket.sockaddr_in(port, host)
61
-
62
60
  test_domains.each do |domain|
63
- begin
64
- sock = Socket.new(domain, :STREAM)
65
- return 0 == sock.connect(addr)
66
- rescue Errno::EAFNOSUPPORT
67
- next # try next domain
68
- rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT
69
- return false
70
- ensure
71
- if not sock.nil?
72
- sock.close
73
- end
61
+ addr = get_addr(host, port, domain)
62
+ if addr.nil?
63
+ next
64
+ end
65
+
66
+ if test_sockaddr(addr, domain)
67
+ return true
74
68
  end
75
69
  end
70
+
71
+ return false
76
72
  end
77
73
 
78
74
  ##
@@ -155,6 +151,54 @@ module Unobtainium
155
151
 
156
152
  return false
157
153
  end
154
+
155
+ # Create an address for the domain. That's a little convoluted, but it
156
+ # avoids errors with trying to use INET addresses with INET6 and vice versa.
157
+ def get_addr(host, port, domain)
158
+ begin
159
+ infos = Addrinfo.getaddrinfo(host, port, domain, :STREAM)
160
+ infos.each do |info|
161
+ if info.pfamily == Socket.const_get('PF_' + domain.to_s)
162
+ return info.to_sockaddr
163
+ end
164
+ end
165
+ rescue SocketError
166
+ # Host does not resolve in this domain
167
+ return nil
168
+ end
169
+
170
+ return nil
171
+ end
172
+
173
+ # Test a particular sockaddr
174
+ def test_sockaddr(addr, domain)
175
+ sock = Socket.new(domain, :STREAM)
176
+
177
+ connected = false
178
+ loop do
179
+ begin
180
+ sock.connect_nonblock(addr)
181
+ rescue Errno::EINPROGRESS
182
+ if not IO.select(nil, [sock], nil, 1)
183
+ # Timed out, retry?
184
+ next
185
+ end
186
+ rescue Errno::EISCONN
187
+ connected = true
188
+ break
189
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
190
+ # Could not connect
191
+ break
192
+ rescue Errno::EINVAL, Errno::EAFNOSUPPORT
193
+ # Unsupported protocol
194
+ break
195
+ end
196
+ end
197
+
198
+ sock.close
199
+
200
+ return connected
201
+ end
158
202
  end # module PortScanner
159
203
  end # module Support
160
204
  end # module Unobtainium
@@ -65,6 +65,9 @@ module Unobtainium
65
65
  raise "Command already running!"
66
66
  end
67
67
 
68
+ # Reset everything
69
+ reset
70
+
68
71
  # Capture options; pipes for stdout and stderr
69
72
  @stdout, @wout = IO.pipe
70
73
  @stderr, @werr = IO.pipe
@@ -77,6 +80,13 @@ module Unobtainium
77
80
  return @pid
78
81
  end
79
82
 
83
+ ##
84
+ # Resets stdout, stderr, etc. - does not kill a process, see #kill
85
+ # instead.
86
+ def reset
87
+ cleanup(true)
88
+ end
89
+
80
90
  ##
81
91
  # Wait for the command to exit.
82
92
  # @return [Process::Status] exit status of the command.
@@ -135,9 +145,6 @@ module Unobtainium
135
145
  end
136
146
  # rubocop:enable Lint/HandleExceptions
137
147
  end
138
-
139
- # Clean up everything
140
- cleanup(true)
141
148
  end
142
149
 
143
150
  ##
@@ -145,6 +152,7 @@ module Unobtainium
145
152
  # Use together with Runtime class to clean up any commands at exit.
146
153
  def destroy
147
154
  kill
155
+ reset
148
156
  end
149
157
 
150
158
  private
@@ -8,5 +8,5 @@
8
8
  #
9
9
  module Unobtainium
10
10
  # The current release version
11
- VERSION = "0.4.0".freeze
11
+ VERSION = "0.5.0".freeze
12
12
  end
@@ -8,31 +8,32 @@ describe ::Unobtainium::Support::PortScanner do
8
8
  def connect_mock(_, addr)
9
9
  port, = Socket.unpack_sockaddr_in(addr)
10
10
  if port == 1234 or port == 4321
11
- return 0
11
+ raise Errno::EISCONN
12
12
  end
13
13
  raise Errno::ECONNREFUSED
14
14
  end
15
15
 
16
16
  describe "port_open?" do
17
17
  it "detects an open port correctly" do
18
- allow_any_instance_of(Socket).to receive(:connect).and_return(0)
18
+ allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
19
+ Errno::EISCONN)
19
20
  expect(tester.port_open?('localhost', 1234)).to be_truthy
20
21
  end
21
22
 
22
23
  it "detects a closed port correctly" do
23
- allow_any_instance_of(Socket).to receive(:connect).and_raise(
24
+ allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
24
25
  Errno::ECONNREFUSED)
25
26
  expect(tester.port_open?('localhost', 1234)).to be_falsy
26
27
  end
27
28
 
28
29
  it "handles a single domain parameter" do
29
- allow_any_instance_of(Socket).to receive(:connect).and_raise(
30
+ allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
30
31
  Errno::ECONNREFUSED)
31
32
  expect(tester.port_open?('localhost', 1234, :INET)).to be_falsy
32
33
  end
33
34
 
34
35
  it "handles many domain parameters" do
35
- allow_any_instance_of(Socket).to receive(:connect).and_raise(
36
+ allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
36
37
  Errno::ECONNREFUSED)
37
38
  expect(tester.port_open?('localhost', 1234, [:INET, :INET6])).to be_falsy
38
39
  end
@@ -53,7 +54,7 @@ describe ::Unobtainium::Support::PortScanner do
53
54
  end
54
55
 
55
56
  it "finds an open port in a range" do
56
- allow_any_instance_of(Socket).to receive(:connect) do |sock, addr|
57
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
57
58
  connect_mock(sock, addr)
58
59
  end
59
60
 
@@ -61,7 +62,7 @@ describe ::Unobtainium::Support::PortScanner do
61
62
  end
62
63
 
63
64
  it "finds an open port in an array" do
64
- allow_any_instance_of(Socket).to receive(:connect) do |sock, addr|
65
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
65
66
  connect_mock(sock, addr)
66
67
  end
67
68
 
@@ -69,7 +70,7 @@ describe ::Unobtainium::Support::PortScanner do
69
70
  end
70
71
 
71
72
  it "doesn't find an open port in a range" do
72
- allow_any_instance_of(Socket).to receive(:connect) do |sock, addr|
73
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
73
74
  connect_mock(sock, addr)
74
75
  end
75
76
 
@@ -77,7 +78,7 @@ describe ::Unobtainium::Support::PortScanner do
77
78
  end
78
79
 
79
80
  it "doesn't find an open port in an array" do
80
- allow_any_instance_of(Socket).to receive(:connect) do |sock, addr|
81
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
81
82
  connect_mock(sock, addr)
82
83
  end
83
84
 
@@ -85,7 +86,7 @@ describe ::Unobtainium::Support::PortScanner do
85
86
  end
86
87
 
87
88
  it "finds an open port in mixed arguments" do
88
- allow_any_instance_of(Socket).to receive(:connect) do |sock, addr|
89
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
89
90
  connect_mock(sock, addr)
90
91
  end
91
92
 
@@ -101,7 +102,7 @@ describe ::Unobtainium::Support::PortScanner do
101
102
  end
102
103
 
103
104
  it "can abort after the first find" do
104
- allow_any_instance_of(Socket).to receive(:connect) do |sock, addr|
105
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
105
106
  connect_mock(sock, addr)
106
107
  end
107
108
 
@@ -109,7 +110,7 @@ describe ::Unobtainium::Support::PortScanner do
109
110
  end
110
111
 
111
112
  it "can scan for closed/available ports" do
112
- allow_any_instance_of(Socket).to receive(:connect) do |sock, addr|
113
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
113
114
  connect_mock(sock, addr)
114
115
  end
115
116
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unobtainium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Finkhaeuser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-03 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler