Module: Scarpe::Components::PortHelpers
- Defined in:
- scarpe-components/lib/scarpe/components/port_helpers.rb
Constant Summary collapse
- MAX_SERVER_STARTUP_WAIT =
5.0
Instance Method Summary collapse
- #port_working?(ip, port_num) ⇒ Boolean
- #wait_until_port_working(ip, port_num, max_wait: MAX_SERVER_STARTUP_WAIT) ⇒ Object
Instance Method Details
#port_working?(ip, port_num) ⇒ Boolean
9 10 11 12 13 14 15 16 |
# File 'scarpe-components/lib/scarpe/components/port_helpers.rb', line 9 def port_working?(ip, port_num) begin TCPSocket.new(ip, port_num) rescue Errno::ECONNREFUSED return false end return true end |
#wait_until_port_working(ip, port_num, max_wait: MAX_SERVER_STARTUP_WAIT) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'scarpe-components/lib/scarpe/components/port_helpers.rb', line 18 def wait_until_port_working(ip, port_num, max_wait: MAX_SERVER_STARTUP_WAIT) t_start = Time.now loop do if Time.now - t_start > max_wait raise "Server on port #{port_num} didn't start up in time!" end sleep 0.1 return if port_working?(ip, port_num) end end |