Skip to content

Commit b8b0bcc

Browse files
committed
[GR-15950] Use a random port for Bundler tests to avoid binding conflicts.
PullRequest: truffleruby/852
2 parents a6fcc19 + c1b4300 commit b8b0bcc

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

test/truffle/common.sh.inc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ function test_server {
99
serverpid=$!
1010
echo "Server PID: $serverpid"
1111

12-
ports=""
13-
while [ -z "$ports" ]; do
14-
ports=$(lsof -P -i 4 -a -p $serverpid -Fn | grep nlocalhost | cut -d ':' -f 2)
15-
sleep 1
16-
done
12+
ports=$(jt find_ports_for_pid "$serverpid")
1713

1814
if [[ $(echo "$ports" | wc -l) -gt 1 ]]; then
1915
echo "More than one port opened!" >&2

tool/jt.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,14 @@ def test_ecosystem(*args)
12571257
end
12581258
private :test_ecosystem
12591259

1260+
def find_ports_for_pid(pid)
1261+
while (ports = `lsof -P -i 4 -a -p #{pid} -Fn | grep nlocalhost | cut -d ':' -f 2`.strip).empty?
1262+
sleep 1
1263+
end
1264+
puts ports
1265+
ports
1266+
end
1267+
12601268
def test_bundle(*args)
12611269
require 'tmpdir'
12621270

@@ -1267,8 +1275,12 @@ def test_bundle(*args)
12671275
]
12681276
gems = %w[algebrick]
12691277

1270-
gem_server = spawn('gem', 'server', '-b', '127.0.0.1', '-d', "#{gem_test_pack}/gems")
1278+
gem_server = spawn('gem', 'server', '-b', '127.0.0.1', '-p', '0', '-d', "#{gem_test_pack}/gems")
12711279
begin
1280+
ports = find_ports_for_pid(gem_server)
1281+
raise "More than one port opened" if ports.lines.size > 1
1282+
port = Integer(ports)
1283+
12721284
bundle_install_flags.each do |install_flags|
12731285
puts "Testing Bundler with install flags: #{install_flags}"
12741286
gems.each do |gem_name|
@@ -1289,12 +1301,10 @@ def test_bundle(*args)
12891301
# add bin from gem_home to PATH
12901302
'PATH' => ["#{gem_home}/bin", ENV['PATH']].join(File::PATH_SEPARATOR))
12911303

1292-
options = [
1293-
'--experimental-options',
1294-
'--exceptions-print-java',
1295-
]
1304+
options = %w[--experimental-options --exceptions-print-java]
12961305

1297-
gemserver_source = %w[--clear-sources --source http://localhost:8808]
1306+
run_ruby(environment, *args, *options,
1307+
'-Sbundle', 'config', '--local', 'mirror.http://localhost:8808', "http://localhost:#{port}")
12981308

12991309
run_ruby(environment, *args, *options,
13001310
'-Sbundle', 'install', '-V', *install_flags)

0 commit comments

Comments
 (0)