Skip to content

Commit 72ef9bc

Browse files
MatthiasJobstpre-commit-ci[bot]mathbunnyru
authored
Healthcheck gives correct result even behind proxy (#1964)
* Fixed #1962 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update base-notebook/docker_healthcheck.py Use empty string instead of None Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
1 parent afe6311 commit 72ef9bc

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

base-notebook/docker_healthcheck.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
url = json.loads(json_file.read_bytes())["url"]
1717
url = url + "api"
1818

19-
r = requests.get(url, verify=False) # request without SSL verification
19+
proxies = {
20+
"http": "",
21+
"https": "",
22+
}
23+
24+
r = requests.get(url, proxies=proxies, verify=False) # request without SSL verification
2025
r.raise_for_status()
2126
print(r.content)

tests/base-notebook/test_healthcheck.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,53 @@ def test_health(
6969
assert get_health(running_container) == "healthy"
7070

7171

72+
@pytest.mark.parametrize(
73+
"env,cmd,user",
74+
[
75+
(
76+
["HTTPS_PROXY=host.docker.internal", "HTTP_PROXY=host.docker.internal"],
77+
None,
78+
None,
79+
),
80+
(
81+
[
82+
"NB_USER=testuser",
83+
"CHOWN_HOME=1",
84+
"JUPYTER_PORT=8123",
85+
"HTTPS_PROXY=host.docker.internal",
86+
"HTTP_PROXY=host.docker.internal",
87+
],
88+
["start-notebook.sh", "--ServerApp.base_url=/test"],
89+
"root",
90+
),
91+
],
92+
)
93+
def test_health_proxy(
94+
container: TrackedContainer,
95+
env: Optional[list[str]],
96+
cmd: Optional[list[str]],
97+
user: Optional[str],
98+
) -> None:
99+
running_container = container.run_detached(
100+
tty=True,
101+
environment=env,
102+
command=cmd,
103+
user=user,
104+
)
105+
106+
# sleeping some time to let the server start
107+
time_spent = 0.0
108+
wait_time = 0.1
109+
time_limit = 15
110+
while time_spent < time_limit:
111+
time.sleep(wait_time)
112+
time_spent += wait_time
113+
if get_health(running_container) == "healthy":
114+
return
115+
116+
assert get_health(running_container) == "healthy"
117+
118+
72119
@pytest.mark.parametrize(
73120
"env,cmd,user",
74121
[

0 commit comments

Comments
 (0)