-
Notifications
You must be signed in to change notification settings - Fork 3k
Refactor healthcheck tests to use one function #2254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,32 @@ | |
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def get_healthy_status( | ||
container: TrackedContainer, | ||
env: list[str] | None, | ||
cmd: list[str] | None, | ||
user: str | None, | ||
) -> str: | ||
running_container = container.run_detached( | ||
tty=True, | ||
environment=env, | ||
command=cmd, | ||
user=user, | ||
) | ||
|
||
# giving some time to let the server start | ||
finish_time = time.time() + 10 | ||
sleep_time = 1 | ||
while time.time() < finish_time: | ||
time.sleep(sleep_time) | ||
|
||
status = get_health(running_container) | ||
if status == "healthy": | ||
return status | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fast exit in case get_health reports the status is healthy |
||
|
||
return get_health(running_container) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"env,cmd,user", | ||
[ | ||
|
@@ -60,22 +86,7 @@ def test_healthy( | |
cmd: list[str] | None, | ||
user: str | None, | ||
) -> None: | ||
running_container = container.run_detached( | ||
tty=True, | ||
environment=env, | ||
command=cmd, | ||
user=user, | ||
) | ||
|
||
# giving some time to let the server start | ||
finish_time = time.time() + 10 | ||
sleep_time = 0.1 | ||
while time.time() < finish_time: | ||
time.sleep(sleep_time) | ||
if get_health(running_container) == "healthy": | ||
return | ||
|
||
assert get_health(running_container) == "healthy" | ||
assert get_healthy_status(container, env, cmd, user) == "healthy" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -108,22 +119,7 @@ def test_healthy_with_proxy( | |
cmd: list[str] | None, | ||
user: str | None, | ||
) -> None: | ||
running_container = container.run_detached( | ||
tty=True, | ||
environment=env, | ||
command=cmd, | ||
user=user, | ||
) | ||
|
||
# giving some time to let the server start | ||
finish_time = time.time() + 10 | ||
sleep_time = 0.1 | ||
while time.time() < finish_time: | ||
time.sleep(sleep_time) | ||
if get_health(running_container) == "healthy": | ||
return | ||
|
||
assert get_health(running_container) == "healthy" | ||
assert get_healthy_status(container, env, cmd, user) == "healthy" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -145,18 +141,6 @@ def test_not_healthy( | |
env: list[str] | None, | ||
cmd: list[str] | None, | ||
) -> None: | ||
running_container = container.run_detached( | ||
tty=True, | ||
environment=env, | ||
command=cmd, | ||
) | ||
|
||
# giving some time to let the server start | ||
finish_time = time.time() + 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
sleep_time = 0.1 | ||
while time.time() < finish_time: | ||
time.sleep(sleep_time) | ||
if get_health(running_container) == "healthy": | ||
raise RuntimeError("Container should not be healthy for this testcase") | ||
|
||
assert get_health(running_container) != "healthy" | ||
assert ( | ||
get_healthy_status(container, env, cmd, user=None) != "healthy" | ||
), "Container should not be healthy for this testcase" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sleeping 1 second instead of 0.1, because otherwise we produce too much logs when running
pytest
directly