Class: TCPSocket

Inherits:
Object show all
Defined in:
lib/webrat/culerity/core_ext/socket.rb,
lib/webrat/core_extensions/tcp_socket.rb

Class Method Summary collapse

Class Method Details

.wait_for_service(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/webrat/culerity/core_ext/socket.rb', line 5

def self.wait_for_service(options)
  socket = nil
  Timeout::timeout(options[:timeout] || 20) do
    loop do
      begin
        socket = TCPSocket.new(options[:host], options[:port])
        return
      rescue Errno::ECONNREFUSED
        puts ".\n"
        sleep 2
      end
    end
  end
ensure
  socket.close unless socket.nil?
end

.wait_for_service_termination_with_timeout(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/webrat/core_extensions/tcp_socket.rb', line 15

def self.wait_for_service_termination_with_timeout(options)
  start_time = Time.now

  while listening_service?(options)
    verbose_wait

    if options[:timeout] && (Time.now > start_time + options[:timeout])
      raise SocketError.new("Socket did not terminate within #{options[:timeout]} seconds")
    end
  end
end

.wait_for_service_with_timeout(options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/webrat/core_extensions/tcp_socket.rb', line 3

def self.wait_for_service_with_timeout(options)
  start_time = Time.now

  until listening_service?(options)
    verbose_wait

    if options[:timeout] && (Time.now > start_time + options[:timeout])
      raise SocketError.new("Socket did not open within #{options[:timeout]} seconds")
    end
  end
end