percy-common 1.4.0 → 1.4.1

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: da785e6e731d99a3e9a2443232e3dafc8f9e7139
4
- data.tar.gz: 662d50ea490653c199ca08a243348e0c41340bae
3
+ metadata.gz: 711a2ac9579789989cc96bb04e0f0b3b4449be39
4
+ data.tar.gz: 53358f2998aaaba1f64178c2bf948792656791c8
5
5
  SHA512:
6
- metadata.gz: 101b3fda6f5c3fe97a81e6539eb5bbdd7f77ae720ebe19a808fe91d0231d6f5e7376291a12ce1091339c03c5a498a8fb6fc2e1113fb340ac8a2c38d77dde1a98
7
- data.tar.gz: 4d23ec8e50cba05655c1dad3a3396d556bcb4904d21df120d2622e1f60f147d4073b99050ffd7ca2441d8156a8e6a3cfe4c118207c5bc5718c715eea68dbbfc3
6
+ metadata.gz: 001cb2a5c604a329b26ecbe8b80d78e6a773dc40ab4a0df2baac28c0820938d32eb32bd86ec2d03f3b838cfaad3e3f4e2f316c3a52d7da1696e3ab025dc19981
7
+ data.tar.gz: b77f16727712ee9c572478917d4b09f6f2e2a62c60f25189c0efba0f62446097f7c74e5d6ed2a4a04531e1efeed39730f6ecee6e6625920ac2803f0d0c178402
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  module Common
3
- VERSION = '1.4.0'.freeze
3
+ VERSION = '1.4.1'.freeze
4
4
  end
5
5
  end
@@ -3,14 +3,29 @@ require 'excon'
3
3
 
4
4
  module Percy
5
5
  class NetworkHelpers
6
+ MIN_PORT = 1_024 # 0-1023 are not available without privilege
7
+ MAX_PORT = 65_535 # (2^16) -1
8
+ MAX_PORT_ATTEMPTS = 50
9
+
6
10
  class ServerDown < RuntimeError; end
11
+ class OpenPortNotFound < RuntimeError; end
7
12
 
8
13
  def self.random_open_port
9
- # Using a port of "0" relies on the system to pick an open port.
10
- server = TCPServer.new('127.0.0.1', 0)
11
- port = server.addr[1]
12
- server.close
13
- port
14
+ MAX_PORT_ATTEMPTS.times do
15
+ port = rand(MIN_PORT..MAX_PORT)
16
+ return port if port_open? port
17
+ end
18
+
19
+ raise OpenPortNotFound
20
+ end
21
+
22
+ def self.port_open?(port)
23
+ begin
24
+ TCPServer.new(port).close
25
+ true
26
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::EADDRINUSE
27
+ false
28
+ end
14
29
  end
15
30
 
16
31
  def self.verify_healthcheck(url:, expected_body: 'ok', retry_wait_seconds: 0.5)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-08 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogstatsd-ruby
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  requirements: []
168
168
  rubyforge_project:
169
- rubygems_version: 2.4.8
169
+ rubygems_version: 2.6.13
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Server-side common library for Percy.