Choose random host port in tests

This commit is contained in:
Ayaz Salikhov
2022-02-14 14:15:08 +03:00
parent 1ef883888b
commit 5ebb4bd0f2
4 changed files with 23 additions and 8 deletions

View File

@@ -16,9 +16,11 @@ def test_cli_args(container: TrackedContainer, http_client: requests.Session) ->
"""Container should respect notebook server command line args
(e.g., disabling token security)"""
running_container = container.run_detached(
command=["start-notebook.sh", "--NotebookApp.token=''"]
command=["start-notebook.sh", "--NotebookApp.token=''"],
ports={"8888/tcp": None},
)
resp = http_client.get("http://localhost:8888")
host_port = container.get_host_port("8888/tcp")
resp = http_client.get("http://localhost:" + host_port)
resp.raise_for_status()
logs = running_container.logs().decode("utf-8")
LOGGER.debug(logs)
@@ -35,13 +37,17 @@ def test_unsigned_ssl(
"""Container should generate a self-signed SSL certificate
and notebook server should use it to enable HTTPS.
"""
running_container = container.run_detached(environment=["GEN_CERT=yes"])
running_container = container.run_detached(
environment=["GEN_CERT=yes"],
ports={"8888/tcp": None},
)
host_port = container.get_host_port("8888/tcp")
# NOTE: The requests.Session backing the http_client fixture does not retry
# properly while the server is booting up. An SSL handshake error seems to
# abort the retry logic. Forcing a long sleep for the moment until I have
# time to dig more.
time.sleep(5)
resp = http_client.get("https://localhost:8888", verify=False)
resp = http_client.get("https://localhost:" + host_port, verify=False)
resp.raise_for_status()
assert "login_submit" in resp.text
logs = running_container.logs().decode("utf-8")