From a5ced121075d9653db2673758c4d6eb2a6b89252 Mon Sep 17 00:00:00 2001 From: Liora Milbaum Date: Thu, 28 Mar 2024 22:46:22 +0200 Subject: [PATCH] chatbot tests Signed-off-by: Liora Milbaum --- .github/workflows/chatbot.yaml | 6 +++++ .github/workflows/model_servers.yaml | 6 +++++ .../chatbot/tests/conftest.py | 23 +++++++++++++++++++ .../chatbot/tests/test_alive.py | 14 +++++++++-- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 recipes/natural_language_processing/chatbot/tests/conftest.py diff --git a/.github/workflows/chatbot.yaml b/.github/workflows/chatbot.yaml index 8a2865b37..23ed2a473 100644 --- a/.github/workflows/chatbot.yaml +++ b/.github/workflows/chatbot.yaml @@ -4,9 +4,15 @@ on: pull_request: branches: - main + paths: + - ./recipes/natural_language_processing/chatbot/** + - .github/workflows/chatbot.yaml push: branches: - main + paths: + - ./recipes/natural_language_processing/chatbot/** + - .github/workflows/chatbot.yaml env: REGISTRY: ghcr.io diff --git a/.github/workflows/model_servers.yaml b/.github/workflows/model_servers.yaml index d8603bddb..023679320 100644 --- a/.github/workflows/model_servers.yaml +++ b/.github/workflows/model_servers.yaml @@ -4,9 +4,15 @@ on: pull_request: branches: - main + paths: + - ./model_servers/llamacpp_python/** + - .github/workflows/model_servers.yaml push: branches: - main + paths: + - ./model_servers/llamacpp_python/** + - .github/workflows/model_servers.yaml env: REGISTRY: ghcr.io diff --git a/recipes/natural_language_processing/chatbot/tests/conftest.py b/recipes/natural_language_processing/chatbot/tests/conftest.py new file mode 100644 index 000000000..6242ebbe4 --- /dev/null +++ b/recipes/natural_language_processing/chatbot/tests/conftest.py @@ -0,0 +1,23 @@ +import pytest_container +import os + + +CB = pytest_container.Container( + url=f"containers-storage:{os.environ['REGISTRY']}/{os.environ['IMAGE_NAME']}", + extra_environment_variables={ + "MODEL_SERVICE_ENDPOINT": "http://10.88.0.1:8001/v1" + }, + forwarded_ports=[ + pytest_container.PortForwarding( + container_port=8501, + host_port=8501 + ) + ], + extra_launch_args=["--net=host"] + ) + +def pytest_generate_tests(metafunc): + pytest_container.auto_container_parametrize(metafunc) + +def pytest_addoption(parser): + pytest_container.add_logging_level_options(parser) diff --git a/recipes/natural_language_processing/chatbot/tests/test_alive.py b/recipes/natural_language_processing/chatbot/tests/test_alive.py index ace0d4240..a9a7e52bc 100644 --- a/recipes/natural_language_processing/chatbot/tests/test_alive.py +++ b/recipes/natural_language_processing/chatbot/tests/test_alive.py @@ -1,2 +1,12 @@ -def test_placeholder(): - assert 1 == 1 +import pytest_container +from .conftest import CB +import tenacity + +CONTAINER_IMAGES = [CB] + +def test_etc_os_release_present(auto_container: pytest_container.container.ContainerData): + assert auto_container.connection.file("/etc/os-release").exists + +@tenacity.retry(stop=tenacity.stop_after_attempt(5), wait=tenacity.wait_exponential()) +def test_alive(auto_container: pytest_container.container.ContainerData, host): + host.run_expect([0],f"curl http://localhost:{auto_container.forwarded_ports[0].host_port}",).stdout.strip()