Skip to content

Commit

Permalink
rb: Refactor Edge service to use shared service class
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed May 31, 2016
1 parent c4449c6 commit a60cd4d
Showing 1 changed file with 2 additions and 50 deletions.
52 changes: 2 additions & 50 deletions rb/lib/selenium/webdriver/edge/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ module Edge
#

class Service
START_TIMEOUT = 20
SOCKET_LOCK_TIMEOUT = 45
STOP_TIMEOUT = 5
DEFAULT_PORT = 17556
MISSING_TEXT = "Unable to find MicrosoftWebDriver. Please download the server from https://www.microsoft.com/en-us/download/details.aspx?id=48212. More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver."

Expand All @@ -42,54 +39,19 @@ def self.executable_path
)
end

def self.executable_path=(path)
Platform.assert_executable path
@executable_path = path
end

def self.default_service(*extra_args)
new executable_path, DEFAULT_PORT, *extra_args
end

def initialize(executable_path, port, *extra_args)
@executable_path = executable_path
@host = Platform.localhost
@port = Integer(port)

raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1

@extra_args = extra_args
end

def start
Platform.exit_hook { stop } # make sure we don't leave the server running

socket_lock.locked do
find_free_port
start_process
connect_until_stable
end
end

def stop
return if @process.nil? || @process.exited?
private

def stop_server
Net::HTTP.start(@host, @port) do |http|
http.open_timeout = STOP_TIMEOUT / 2
http.read_timeout = STOP_TIMEOUT / 2

http.head("/shutdown")
end
ensure
stop_process
end

def uri
URI.parse "http://#{@host}:#{@port}"
end

def find_free_port
@port = PortProber.above @port
end

def start_process
Expand All @@ -100,12 +62,6 @@ def start_process
@process.start
end

def stop_process
@process.poll_for_exit STOP_TIMEOUT
rescue ChildProcess::TimeoutError
@process.stop STOP_TIMEOUT
end

def connect_until_stable
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT

Expand All @@ -114,10 +70,6 @@ def connect_until_stable
end
end

def socket_lock
@socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
end

end # Service
end # Edge
end # WebDriver
Expand Down

0 comments on commit a60cd4d

Please sign in to comment.