Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/common/child_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TimeoutError < StandardError
POLL_INTERVAL = 0.1

attr_accessor :detach, :env
attr_reader :status
attr_writer :io

def self.build(*command)
Expand Down
8 changes: 8 additions & 0 deletions rb/lib/selenium/webdriver/common/service_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def start
find_free_port
start_process
connect_until_stable
rescue StandardError
stop_process
raise
end
end

Expand Down Expand Up @@ -139,6 +142,11 @@ def connect_until_stable
deadline = current_time + START_TIMEOUT

loop do
if process_exited?
raise Error::WebDriverError,
"#{cannot_connect_error_text}: process exited (#{@process.status || 'status unknown'})"
end

error = check_connection_error
return unless error

Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/child_process.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module Selenium

attr_accessor env: Hash[String, String?]?

attr_reader status: untyped

attr_writer io: untyped

def self.build: (*untyped command) -> untyped
Expand Down
58 changes: 58 additions & 0 deletions rb/spec/unit/selenium/webdriver/common/service_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

require File.expand_path('../spec_helper', __dir__)

module Selenium
module WebDriver
describe ServiceManager do
unless Platform.windows?
let(:driver_dir) { Dir.mktmpdir }

before { WebMock.disable! }

after do
WebMock.enable!
FileUtils.rm_rf(driver_dir)
end

def manager_for(script)
path = File.join(driver_dir, 'fake_driver')
File.write(path, "#!/bin/sh\n#{script}\n")
File.chmod(0o755, path)
described_class.new(Service.chrome(path: path))
end

it 'reports the exit status when the driver exits before accepting connections' do
manager = manager_for('exit 3')

expect { manager.start }.to raise_error(Error::WebDriverError, /process exited \(pid \d+ exit 3\)/)
end

it 'stops the driver when it does not accept connections in time' do
stub_const('Selenium::WebDriver::ServiceManager::START_TIMEOUT', 1)
manager = manager_for('exec sleep 30')

expect { manager.start }.to raise_error(Error::WebDriverError, /ECONNREFUSED/)
expect(manager.instance_variable_get(:@process)).not_to be_alive
end
end
end
end
end
Loading