Skip to content
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

[wip] feat: integration testing #41

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tests = [
'pytest-cov',
'pytest-mock',
'pytest-benchmark[histogram]',
'pytest-dependency',
]
dev = [
'mypy',
Expand Down
79 changes: 79 additions & 0 deletions tests/integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import json
import re

import pytest
import grpc

from conftest import run_cmd_and_assert_exit_code

from armonik.client.results import ArmoniKResults

ENDPOINT = "172.17.63.166:5001"

ansi_codes = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")


def remove_ansi_escapecodes(in_string: str) -> str:
return ansi_codes.sub("", in_string)


@pytest.fixture(scope="session")
def context():
return {"created_session_id": None, "created_result_ids": [], "created_task_ids": []}


@pytest.mark.dependency(name="create_session")
def test_create_session(context):
# Note: we're not testing the serialization here, but more so the interaction of the CLI with the ArmoniK API, hence the nature of this test
create_session_result = run_cmd_and_assert_exit_code(
f"session create --priority 1 --max-duration 01:00:0 --max-retries 2 --endpoint {ENDPOINT}"
)

deserialized_created_session = json.loads(remove_ansi_escapecodes(create_session_result.output))
# Convert result to dict
assert "SessionId" in deserialized_created_session
get_session_result = run_cmd_and_assert_exit_code(
f"session get --endpoint {ENDPOINT} {deserialized_created_session['SessionId']}"
)
deserialized_get_session = json.loads(remove_ansi_escapecodes(get_session_result.output))
assert deserialized_created_session == deserialized_get_session
context["created_session_id"] = deserialized_get_session["SessionId"]


@pytest.mark.dependency(name="create_result", depends=["create_session"])
def test_create_result():
pass


@pytest.mark.dependency(name="create_task", depends=["create_result"])
def test_create_task(context):
# Ideally we'd create the results for payload, expected_output in a step before but since we don't have results merged yet this will do
created_session_id = context["created_session_id"]
grpc_channel = grpc.insecure_channel(ENDPOINT)
results_client = ArmoniKResults(grpc_channel)
result_objects = results_client.create_results_metadata(
[f"payload-{created_session_id}", f"output-{created_session_id}"], created_session_id
)
payload_id = result_objects[f"payload-{created_session_id}"].result_id
expected_output_id = result_objects[f"output-{created_session_id}"].result_id
context["created_result_ids"] = [payload_id, expected_output_id]
create_task_result = run_cmd_and_assert_exit_code(
f"task create --endpoint {ENDPOINT} --session-id {created_session_id} --payload-id {payload_id} --expected-outputs {expected_output_id} --debug"
)
deserialized_created_task = json.loads(remove_ansi_escapecodes(create_task_result.output))
context["created_task_ids"] = [deserialized_created_task["Id"]]
get_task_result = run_cmd_and_assert_exit_code(
f"task get --endpoint {ENDPOINT} {deserialized_created_task['Id']}"
)
deserialized_get_task = json.loads(remove_ansi_escapecodes(get_task_result.output))

assert deserialized_created_task["Id"] == deserialized_get_task[0]["Id"]


@pytest.mark.dependency(name="cleanup", depends=["create_task"])
def test_cleanup(context):
# Delete session and tasks in it (I can never actually delete the results..)
delete_session_result = run_cmd_and_assert_exit_code(
f"session delete --endpoint {ENDPOINT} {context['created_session_id']} --confirm"
)
assert "error" not in delete_session_result.output.lower()
Loading