Skip to content

Commit

Permalink
[rb] fix SeleniumHQ#8525 by limiting concurrent sessions in test to t…
Browse files Browse the repository at this point in the history
…he number of processors detected
  • Loading branch information
titusfortner committed Feb 11, 2021
1 parent 06f5a88 commit 7ce3f0b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
16 changes: 16 additions & 0 deletions rb/lib/selenium/webdriver/common/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ def os
end
end

def processors
case os
when :macosx
((`which hwprefs` != '') ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
when :linux
`cat /proc/cpuinfo | grep processor | wc -l`.to_i
when :unix
`sysctl -n hw.ncpu`.to_i
when :windows
require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor")
cpu.to_enum.first.NumberOfCores
end
end

def ci
if ENV['TRAVIS']
:travis
Expand Down
5 changes: 1 addition & 4 deletions rb/spec/integration/selenium/webdriver/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
module Selenium
module WebDriver
describe Driver do
it_behaves_like 'driver that can be started concurrently', exclude: [{browser: %i[safari safari_preview]},
{driver: :remote,
platform: :linux,
reason: 8525}]
it_behaves_like 'driver that can be started concurrently', exclude: {browser: %i[safari safari_preview]}

it 'creates default capabilities' do
reset_driver! do |driver|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# under the License.

shared_examples_for 'driver that can be started concurrently' do |guard|
before(:all) { quit_driver }

after do
drivers.each(&:quit)
threads.select(&:alive?).each(&:kill)
Expand All @@ -26,8 +28,9 @@
let(:drivers) { [] }
let(:threads) { [] }

it 'starts 3 drivers sequentially', guard do
3.times do
it 'starts multiple drivers sequentially', guard do
expected_count = [4, WebDriver::Platform.processors].min
expected_count.times do
thread = Thread.new do
drivers << create_driver!
end
Expand All @@ -36,7 +39,7 @@
end

expect { threads.each(&:join) }.not_to raise_error
expect(drivers.count).to eq(3)
expect(drivers.count).to eq(expected_count)

# make any wire call
expect { drivers.each(&:title) }.not_to raise_error
Expand Down

0 comments on commit 7ce3f0b

Please sign in to comment.