Skip to content

Commit 2428204

Browse files
authored
Use different HTTP ports in the wizard tests (#1026)
If we use only one specific port, when we run the tests in parallel only one job manages to set up the server, and all the others will use the same. However, the other jobs may need to serve different files, causing unrelated failures in the tests.
1 parent 51dc2e0 commit 2428204

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

test/wizard.jl

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,32 @@ function serve_tgz(req)
5454
HTTP.Response(200, libfoo_tarball_data)
5555
end
5656
HTTP.@register(r, "GET", "/*/source.tar.gz", serve_tgz)
57-
@async HTTP.serve(r, Sockets.localhost, 14444; verbose=false)
57+
port = -1
58+
server = Sockets.TCPServer()
59+
# Try to connect to different ports, in case one is busy. Important in case we
60+
# have multiple parallel builds.
61+
available_ports = 14444:14544
62+
for i in available_ports
63+
try
64+
# Update the global server to shut it down when we are done with it.
65+
global server = Sockets.listen(Sockets.InetAddr(Sockets.localhost, i))
66+
catch e
67+
if e isa Base.IOError
68+
if i == last(available_ports)
69+
# Oh no, this was our last attempt
70+
error("No more ports available for the HTTP server")
71+
end
72+
# If the port is busy, try the next one
73+
continue
74+
else
75+
rethrow(e)
76+
end
77+
end
78+
# All looks good, update the global `port` and start the server
79+
global port = i
80+
@async HTTP.serve(r, Sockets.localhost, port; server=server, verbose=false)
81+
break
82+
end
5883

5984
function readuntil_sift(io::IO, needle)
6085
needle = codeunits(needle)
@@ -127,7 +152,7 @@ end
127152
@testset "Wizard - Downloading" begin
128153
state = step2_state()
129154
with_wizard_output(state, Wizard.step2) do ins, outs
130-
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:14444/a/source.tar.gz")
155+
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:$(port)/a/source.tar.gz")
131156
call_response(ins, outs, "Would you like to download additional sources", "N")
132157
call_response(ins, outs, "Do you require any (binary) dependencies", "N")
133158

@@ -144,7 +169,7 @@ end
144169
call_response(ins, outs, "Select the preferred LLVM version", "\e[B\e[B\e[B\r")
145170
end
146171
# Check that the state is modified appropriately
147-
@test state.source_urls == ["http://127.0.0.1:14444/a/source.tar.gz"]
172+
@test state.source_urls == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
148173
@test getfield.(state.source_files, :hash) == [libfoo_tarball_hash]
149174
@test Set(state.compilers) == Set([:c, :rust, :go])
150175
@test state.preferred_gcc_version == getversion(available_gcc_builds[1])
@@ -155,9 +180,9 @@ end
155180
# Test two tar.gz download
156181
state = step2_state()
157182
with_wizard_output(state, Wizard.step2) do ins, outs
158-
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:14444/a/source.tar.gz")
183+
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:$(port)/a/source.tar.gz")
159184
call_response(ins, outs, "Would you like to download additional sources", "Y")
160-
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:14444/b/source.tar.gz")
185+
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:$(port)/b/source.tar.gz")
161186
call_response(ins, outs, "Would you like to download additional sources", "N")
162187
call_response(ins, outs, "Do you require any (binary) dependencies", "N")
163188

@@ -168,8 +193,8 @@ end
168193
end
169194
# Check that the state is modified appropriately
170195
@test state.source_urls == [
171-
"http://127.0.0.1:14444/a/source.tar.gz",
172-
"http://127.0.0.1:14444/b/source.tar.gz",
196+
"http://127.0.0.1:$(port)/a/source.tar.gz",
197+
"http://127.0.0.1:$(port)/b/source.tar.gz",
173198
]
174199
@test getfield.(state.source_files, :hash) == [
175200
libfoo_tarball_hash,
@@ -193,7 +218,7 @@ end
193218
# Test failure to resolve a dependency
194219
state = step2_state()
195220
@test_logs (:warn, r"Unable to resolve iso_codez_jll") match_mode=:any with_wizard_output(state, Wizard.step2) do ins, outs
196-
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:14444/a/source.tar.gz")
221+
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:$(port)/a/source.tar.gz")
197222
call_response(ins, outs, "Would you like to download additional sources", "N")
198223
call_response(ins, outs, "Do you require any (binary) dependencies", "Y")
199224

@@ -231,7 +256,7 @@ function step3_state()
231256
state = Wizard.WizardState()
232257
state.step = :step34
233258
state.platforms = [Platform("x86_64", "linux")]
234-
state.source_urls = ["http://127.0.0.1:14444/a/source.tar.gz"]
259+
state.source_urls = ["http://127.0.0.1:$(port)/a/source.tar.gz"]
235260
state.source_files = [BinaryBuilder.SetupSource{ArchiveSource}(libfoo_tarball_path, libfoo_tarball_hash, "")]
236261
state.name = "libfoo"
237262
state.version = v"1.0.0"
@@ -425,6 +450,7 @@ end
425450
end
426451
end
427452

453+
close(server)
428454

429455
@testset "GitHub - authentication" begin
430456
withenv("GITHUB_TOKEN" => "") do

0 commit comments

Comments
 (0)