Skip to content

Commit 854782b

Browse files
committed
Fix tests
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent a030566 commit 854782b

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

java/src/org/openqa/selenium/grid/node/config/NodeOptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,12 @@ private Map<WebDriverInfo, Integer> calculateOptimizedCpuDistribution(List<WebDr
453453

454454
// First, allocate sessions for constrained drivers (like Safari)
455455
int remainingCores = DEFAULT_MAX_SESSIONS;
456-
List<WebDriverInfo> constrainedDrivers = new ArrayList<>();
457456
List<WebDriverInfo> flexibleDrivers = new ArrayList<>();
458457

459458
for (WebDriverInfo info : infos) {
460459
if (info.getMaximumSimultaneousSessions() == 1
461460
&& SINGLE_SESSION_DRIVERS.contains(info.getDisplayName().toLowerCase(Locale.ENGLISH))) {
462-
constrainedDrivers.add(info);
461+
// Constrained drivers get exactly 1 session
463462
sessionsPerDriver.put(info, 1);
464463
remainingCores--;
465464
} else {

java/test/org/openqa/selenium/grid/router/StressTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
class StressTest {
5757

5858
private final ExecutorService executor =
59-
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
59+
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 4);
6060
private final List<TearDownFixture> tearDowns = new LinkedList<>();
6161
private Server<?> server;
6262
private Browser browser;
@@ -80,7 +80,7 @@ public void setupServers() {
8080
+ "override-max-sessions = true"
8181
+ "\n"
8282
+ "max-sessions = "
83-
+ Runtime.getRuntime().availableProcessors() * 2
83+
+ Runtime.getRuntime().availableProcessors() * 4
8484
+ "\n"
8585
+ "enable-managed-downloads = true")));
8686
tearDowns.add(deployment);

rb/spec/unit/selenium/server_spec.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@
2323

2424
module Selenium
2525
describe Server do
26-
let(:mock_process) { instance_double(WebDriver::ChildProcess).as_null_object }
26+
let(:mock_process) do
27+
instance_double(WebDriver::ChildProcess).tap do |mock|
28+
allow(mock).to receive(:start)
29+
allow(mock).to receive(:wait)
30+
allow(mock).to receive(:stop)
31+
allow(mock).to receive(:detach=)
32+
allow(mock).to receive(:io)
33+
allow(mock).to receive(:io=)
34+
end
35+
end
2736
let(:mock_poller) { instance_double(WebDriver::SocketPoller, connected?: true, closed?: true) }
2837
let(:repo) { 'https://api.github.com/repos/seleniumhq/selenium/releases' }
2938
let(:port) { WebDriver::PortProber.above(4444) }
@@ -49,7 +58,8 @@ module Selenium
4958
it 'uses the given jar file and port' do
5059
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
5160
allow(WebDriver::ChildProcess).to receive(:build)
52-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234')
61+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234',
62+
'--override-max-sessions', 'true', '--max-sessions', Etc.nprocessors.to_s)
5363
.and_return(mock_process)
5464

5565
server = described_class.new('selenium_server_deploy.jar', port: 1234, background: true)
@@ -58,13 +68,15 @@ module Selenium
5868
server.start
5969
expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
6070
expect(WebDriver::ChildProcess).to have_received(:build)
61-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234')
71+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234',
72+
'--override-max-sessions', 'true', '--max-sessions', Etc.nprocessors.to_s)
6273
end
6374

6475
it 'waits for the server process by default' do
6576
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
6677
allow(WebDriver::ChildProcess).to receive(:build)
67-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
78+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s,
79+
'--override-max-sessions', 'true', '--max-sessions', Etc.nprocessors.to_s)
6880
.and_return(mock_process)
6981

7082
server = described_class.new('selenium_server_deploy.jar', port: port)
@@ -75,14 +87,16 @@ module Selenium
7587

7688
expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
7789
expect(WebDriver::ChildProcess).to have_received(:build)
78-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
90+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s,
91+
'--override-max-sessions', 'true', '--max-sessions', Etc.nprocessors.to_s)
7992
expect(mock_process).to have_received(:wait)
8093
end
8194

8295
it 'adds additional args' do
8396
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
8497
allow(WebDriver::ChildProcess).to receive(:build)
85-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s, 'foo', 'bar')
98+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s,
99+
'--override-max-sessions', 'true', '--max-sessions', Etc.nprocessors.to_s, 'foo', 'bar')
86100
.and_return(mock_process)
87101

88102
server = described_class.new('selenium_server_deploy.jar', port: port, background: true)
@@ -94,7 +108,8 @@ module Selenium
94108
expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
95109
expect(WebDriver::ChildProcess).to have_received(:build)
96110
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone',
97-
'--port', port.to_s, 'foo', 'bar')
111+
'--port', port.to_s, '--override-max-sessions', 'true', '--max-sessions', Etc.nprocessors.to_s,
112+
'foo', 'bar')
98113
end
99114

100115
it 'adds additional JAVA options args' do
@@ -105,6 +120,8 @@ module Selenium
105120
'-jar', 'selenium_server_deploy.jar',
106121
'standalone',
107122
'--port', port.to_s,
123+
'--override-max-sessions', 'true',
124+
'--max-sessions', Etc.nprocessors.to_s,
108125
'foo',
109126
'bar')
110127
.and_return(mock_process)
@@ -197,7 +214,8 @@ module Selenium
197214
it 'raises Selenium::Server::Error if the server is not launched within the timeout' do
198215
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
199216
allow(WebDriver::ChildProcess).to receive(:build)
200-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
217+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s,
218+
'--override-max-sessions', 'true', '--max-sessions', Etc.nprocessors.to_s)
201219
.and_return(mock_process)
202220

203221
poller = instance_double(WebDriver::SocketPoller)

0 commit comments

Comments
 (0)