lib/tcp_socket_extension.rb in selenium-client-1.2.10 vs lib/tcp_socket_extension.rb in selenium-client-1.2.11
- old
+ new
@@ -2,22 +2,31 @@
require 'socket'
class TCPSocket
def self.wait_for_service(options)
- socket = nil
+ verbose_wait until listening_service?(options)
+ end
+
+ def self.wait_for_service_termination(options)
+ verbose_wait while listening_service?(options)
+ end
+
+ def self.listening_service?(options)
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
+ begin
+ socket = TCPSocket.new(options[:host], options[:port])
+ socket.close unless socket.nil?
+ true
+ rescue Errno::ECONNREFUSED,
+ Errno::EBADF # Windows
+ false
end
end
- ensure
- socket.close unless socket.nil?
end
-
+
+ def self.verbose_wait
+ puts ".\n"
+ sleep 2
+ end
+
end
\ No newline at end of file