Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .github/workflows/test-db-versions-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ jobs:
uses: exasol/python-toolbox/.github/actions/[email protected]
with:
python-version: "3.10"
- name: Log GPU environment
run: |
echo Running nvidia-smi
nvidia-smi
echo Running nvidia-ctk --version
nvidia-ctk --version


- name: Run GPU Tests
run: poetry run -- nox -s run-all-tests -- --db-version='${{ matrix.exasol_version }}' --test-set=gpu-only
1 change: 1 addition & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- #534: Converted integration API test to pytest - test_populate_data.py
- #534: Converted integration API test to pytest - test_hash_symlink_loops.py
- #534: Converted integration API test to pytest - test_termination_handler.py
- #534: Converted integration API test to pytest - test_test_container_reuse.py

## features
- #517: Added docker-db 2025-1-3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

TEST_CONTAINER_ROOT_PATH = Path(__file__).parent / "resources" / "test_container"
TEST_DATA_ROOT_PATH = Path(__file__).parent / "resources" / "test_data"
TEST_CONTAINER_REUSE_ROOT_PATH = (
Path(__file__).parent / "resources" / "test_test_container_reuse"
)

FULL_TEST_CONTAINER_PATH = TEST_CONTAINER_ROOT_PATH / "full"
MOCK_TEST_CONTAINER_PATH = TEST_CONTAINER_ROOT_PATH / "mock"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def run_task(self):


class TestContainerReuseTest(unittest.TestCase):
"""
Deprecated. Replaced by "./test/integration/test_test_container_reuse.py"
"""

def setUp(self):
resource_directory = Path(
Expand Down
201 changes: 201 additions & 0 deletions test/integration/test_test_container_reuse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import shutil
from pathlib import Path
from typing import Any

import luigi
import pytest

from exasol_integration_test_docker_environment.lib.base.dependency_logger_base_task import (
DependencyLoggerBaseTask,
)
from exasol_integration_test_docker_environment.lib.base.docker_base_task import (
DockerBaseTask,
)
from exasol_integration_test_docker_environment.lib.base.run_task import (
generate_root_task,
)
from exasol_integration_test_docker_environment.lib.docker import ContextDockerClient
from exasol_integration_test_docker_environment.lib.models.config.build_config import (
set_build_config,
)
from exasol_integration_test_docker_environment.lib.models.config.docker_config import (
set_docker_repository_config,
)
from exasol_integration_test_docker_environment.lib.models.data.container_info import (
ContainerInfo,
)
from exasol_integration_test_docker_environment.lib.models.data.test_container_content_description import (
TestContainerContentDescription,
)
from exasol_integration_test_docker_environment.lib.test_environment.parameter.test_container_parameter import (
TestContainerParameter,
)
from exasol_integration_test_docker_environment.lib.test_environment.prepare_network_for_test_environment import (
PrepareDockerNetworkForTestEnvironment,
)
from exasol_integration_test_docker_environment.lib.test_environment.spawn_test_container import (
SpawnTestContainer,
)
from exasol_integration_test_docker_environment.test.get_test_container_content import (
TEST_CONTAINER_REUSE_ROOT_PATH,
)
from exasol_integration_test_docker_environment.testing import luigi_utils


class TestTask(DockerBaseTask, TestContainerParameter):
reuse = luigi.BoolParameter()
attempt = luigi.IntParameter()

def run_task(self):
docker_network_task_1 = self.create_child_task(
task_class=PrepareDockerNetworkForTestEnvironment,
environment_name="test_environment_TestContainerReuseTest",
network_name="docker_network_TestContainerReuseTest",
test_container_name="test_container_TestContainerReuseTest",
db_container_name="db_container_TestContainerReuseTest",
reuse=self.reuse,
no_cleanup_after_success=True,
no_cleanup_after_failure=False,
attempt=self.attempt,
)
self.docker_network_future_1 = yield from self.run_dependencies(
docker_network_task_1
)

test_container_task_1 = self.create_child_task(
task_class=SpawnTestContainer,
environment_name="test_environment_TestContainerReuseTest",
test_container_name="test_container_TestContainerReuseTest",
network_info=self.docker_network_future_1.get_output(),
ip_address_index_in_subnet=2,
attempt=self.attempt,
reuse_test_container=self.reuse,
no_test_container_cleanup_after_success=True,
no_test_container_cleanup_after_failure=False,
test_container_content=self.test_container_content,
)
test_container_future_1 = yield from self.run_dependencies(
test_container_task_1
)
container_info: ContainerInfo = test_container_future_1.get_output() # type: ignore
with ContextDockerClient() as docker_client:
container = docker_client.containers.get(container_info.container_name)
self.return_object(
{"container_id": container.id, "image_id": container.image.id}
)


def _setup_luigi_config(output_directory: Path, docker_repository_name: str):
set_build_config(
force_rebuild=False,
force_pull=False,
force_rebuild_from=(),
log_build_context_content=False,
output_directory=str(output_directory),
cache_directory="",
build_name="",
temporary_base_directory="/tmp",
)
set_docker_repository_config(
docker_password=None,
docker_repository_name=docker_repository_name,
docker_username=None,
tag_prefix="",
kind="target",
)


@pytest.fixture
def working_directory(tmp_path_factory):
resource_directory = TEST_CONTAINER_REUSE_ROOT_PATH

temp_directory = tmp_path_factory.mktemp("container")
output_directory = tmp_path_factory.mktemp("output")
working_directory = shutil.copytree(
resource_directory, temp_directory / "test_test_container_reuse"
)
docker_repository_name = "test_test_container_reuse"
_setup_luigi_config(
output_directory=output_directory, docker_repository_name=docker_repository_name
)
luigi_utils.clean(docker_repository_name)
yield working_directory
luigi_utils.clean(docker_repository_name)


def _dockerfile(working_directory: Path):
return working_directory / "tests" / "Dockerfile"


def _get_test_container_content(
working_directory: Path,
) -> TestContainerContentDescription:
return TestContainerContentDescription(
docker_file=str(_dockerfile(working_directory)),
build_files_and_directories=[],
runtime_mappings=[],
)


def run1(working_directory: Path) -> dict[str, Any]:
task = generate_root_task(
task_class=TestTask,
reuse=False,
attempt=1,
test_container_content=_get_test_container_content(working_directory),
)
try:
success = luigi.build([task], workers=1, local_scheduler=True, log_level="INFO")
if success:
result = task.get_result()
task.cleanup(True)
return result
else:
raise Exception("Task failed")
except Exception as e:
task.cleanup(False)
raise RuntimeError("Error spawning test environment") from e


def run2(working_directory: Path) -> tuple[DependencyLoggerBaseTask, dict[str, Any]]:
task = generate_root_task(
task_class=TestTask,
reuse=True,
attempt=2,
test_container_content=_get_test_container_content(working_directory),
)
try:
success = luigi.build([task], workers=1, local_scheduler=True, log_level="INFO")
if success:
return task, task.get_result()
else:
raise Exception("Task failed")
except Exception as e:
task.cleanup(False)
raise RuntimeError("Error spawning test environment") from e


def test_test_container_no_reuse_after_change(working_directory):
p1 = run1(working_directory)
with _dockerfile(working_directory).open("a") as f:
f.write("\n#Test\n")
task, p2 = run2(working_directory)
assert "container_id" in p1
assert "image_id" in p1
assert "container_id" in p2
assert "image_id" in p2
print(p1)
print(p2)
assert p1 != p2
task.cleanup(False) # Cleanup docker container/image.


def test_test_container_reuse(working_directory):
p1 = run1(working_directory)
task, p2 = run2(working_directory)
assert "container_id" in p1
assert "image_id" in p1
print(p1)
print(p2)
assert p1 == p2
task.cleanup(False)
Loading