Class: TCPSocket
Overview
Borrowed from Webrat and Selenium client, watches for TCP port liveness of the spawned server.
Class Method Summary collapse
- .listening_service?(options) ⇒ Boolean
- .verbose_wait ⇒ Object
- .wait_for_service(options) ⇒ Object
- .wait_for_service_termination(options) ⇒ Object
- .wait_for_service_termination_with_timeout(options) ⇒ Object
- .wait_for_service_with_timeout(options) ⇒ Object
Class Method Details
.listening_service?(options) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/riak/util/tcp_socket_extensions.rb', line 17 def self.listening_service?() Timeout::timeout([:timeout] || 20) do begin socket = TCPSocket.new([:host], [:port]) socket.close unless socket.nil? true rescue Errno::ECONNREFUSED, Errno::EBADF # Windows false end end end |
.verbose_wait ⇒ Object
30 31 32 33 |
# File 'lib/riak/util/tcp_socket_extensions.rb', line 30 def self.verbose_wait # Removed the puts call so as not to clutter up test output. sleep 2 end |
.wait_for_service(options) ⇒ Object
9 10 11 |
# File 'lib/riak/util/tcp_socket_extensions.rb', line 9 def self.wait_for_service() verbose_wait until listening_service?() end |
.wait_for_service_termination(options) ⇒ Object
13 14 15 |
# File 'lib/riak/util/tcp_socket_extensions.rb', line 13 def self.wait_for_service_termination() verbose_wait while listening_service?() end |
.wait_for_service_termination_with_timeout(options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/riak/util/tcp_socket_extensions.rb', line 47 def self.wait_for_service_termination_with_timeout() start_time = Time.now while listening_service?() verbose_wait if [:timeout] && (Time.now > start_time + [:timeout]) raise SocketError.new("Socket did not terminate within #{[:timeout]} seconds") end end end |
.wait_for_service_with_timeout(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/riak/util/tcp_socket_extensions.rb', line 35 def self.wait_for_service_with_timeout() start_time = Time.now until listening_service?() verbose_wait if [:timeout] && (Time.now > start_time + [:timeout]) raise SocketError.new("Socket did not open within #{[:timeout]} seconds") end end end |