Skip to content

Commit 546d59f

Browse files
committed
Java: Wait for test HTTP servers to be ready before running buildless test
1 parent 2d9b249 commit 546d59f

File tree

1 file changed

+20
-3
lines changed
  • java/ql/integration-tests/java/buildless-dependency-different-repository

1 file changed

+20
-3
lines changed

java/ql/integration-tests/java/buildless-dependency-different-repository/test.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import subprocess
22
import logging
3+
import time
4+
import socket
5+
6+
7+
def wait_for_port(port, process, timeout=100):
8+
start = time.time()
9+
while time.time() - start < timeout:
10+
# Check if process died
11+
if process.poll() is not None:
12+
raise RuntimeError(f"Server process exited with code {process.returncode}")
13+
try:
14+
with socket.create_connection(("localhost", port), timeout=1):
15+
return True
16+
except (socket.timeout, ConnectionRefusedError, OSError):
17+
time.sleep(0.2)
18+
raise RuntimeError(f"Port {port} not ready within {timeout}s")
319

420

521
def test(codeql, java):
6-
# Each of these serves the "repo" and "repo2" directories on http://localhost:924[89]
7-
repo_server_process = subprocess.Popen(["python3", "-m", "http.server", "9428", "-b", "localhost"], cwd="repo")
8-
repo_server_process2 = subprocess.Popen(["python3", "-m", "http.server", "9429", "-b", "localhost"], cwd="repo2")
22+
repo_server_process = subprocess.Popen(["python3", "-m", "http.server", "9428", "-b", "localhost"], cwd="repo", stderr=subprocess.PIPE, stdout=subprocess.PIPE)
23+
repo_server_process2 = subprocess.Popen(["python3", "-m", "http.server", "9429", "-b", "localhost"], cwd="repo2", stderr=subprocess.PIPE, stdout=subprocess.PIPE)
924
try:
25+
wait_for_port(9428, repo_server_process)
26+
wait_for_port(9429, repo_server_process2)
1027
codeql.database.create(
1128
extractor_option="buildless=true",
1229
_env={"CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_CLASSPATH_FROM_BUILD_FILES": "true"},

0 commit comments

Comments
 (0)