Skip to content

Commit

Permalink
#200: Fixed reuse database setup (#203)
Browse files Browse the repository at this point in the history
* Refactor test_runner_db_test_task.py

Co-authored-by: Christoph Kuhnke <github@kuhnke.net>
  • Loading branch information
tkilias and ckunki authored Jun 27, 2023
1 parent 5e47e9c commit 5d408ce
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
class TestRunnerDBTestTask(FlavorBaseTask,
SpawnTestEnvironmentParameter,
RunDBTestsInTestConfigParameter):
# TODO execute tests only if the exported container is new build
# - a pulled one is ok,
# - needs change in image-info and export-info)
# - add options force tests
# - only possible if the hash of exaslc also goes into the image hashes

reuse_uploaded_container = luigi.BoolParameter(False, significant=False)
release_goal = luigi.Parameter()

Expand Down Expand Up @@ -62,41 +56,42 @@ def run_task(self):
export_info = export_infos[self.release_goal]
self.test_environment_info = self.get_values_from_future(
self._test_environment_info_future) # type: EnvironmentInfo
reuse_release_container = \
self.reuse_database and \
self.reuse_uploaded_container and \
not export_info.is_new
database_credentials = self.get_database_credentials()
yield from self.upload_container(database_credentials,
export_info,
reuse_release_container)
export_info)
yield from self.populate_test_engine_data(self.test_environment_info, database_credentials)
test_results = yield from self.run_test(self.test_environment_info, export_info)
self.return_object(test_results)

def upload_container(self, database_credentials, export_info, reuse_release_container):
def upload_container(self, database_credentials: DatabaseCredentials, export_info: ExportInfo):
reuse = \
self.reuse_database and \
self.reuse_uploaded_container and \
not export_info.is_new
upload_task = self.create_child_task_with_common_params(
UploadExportedContainer,
export_info=export_info,
environment_name=self.test_environment_info.name,
test_environment_info=self.test_environment_info,
release_name=export_info.name,
reuse_uploaded=reuse_release_container,
reuse_uploaded=reuse,
bucketfs_write_password=database_credentials.bucketfs_write_password
)
yield from self.run_dependencies(upload_task)

def populate_test_engine_data(self, test_environment_info: EnvironmentInfo,
database_credentials: DatabaseCredentials) -> None:
task = self.create_child_task(
PopulateTestEngine,
test_environment_info=test_environment_info,
environment_name=self.test_environment_info.name,
db_user=database_credentials.db_user,
db_password=database_credentials.db_password,
bucketfs_write_password=database_credentials.bucketfs_write_password
)
yield from self.run_dependencies(task)
reuse = self.reuse_database_setup and self.test_environment_info.database_info.reused
if not reuse:
task = self.create_child_task(
PopulateTestEngine,
test_environment_info=test_environment_info,
environment_name=self.test_environment_info.name,
db_user=database_credentials.db_user,
db_password=database_credentials.db_password,
bucketfs_write_password=database_credentials.bucketfs_write_password
)
yield from self.run_dependencies(task)

def get_database_credentials(self) -> DatabaseCredentials:
if self.environment_type == EnvironmentType.external_db:
Expand Down
60 changes: 60 additions & 0 deletions test/test_run_db_test_docker_db_reuse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import unittest
from pathlib import Path

from exasol_integration_test_docker_environment.lib.docker import ContextDockerClient
from exasol_integration_test_docker_environment.lib.docker.container.utils import remove_docker_container

import utils as exaslct_utils

from typing import Dict, List


def get_docker_container_ids(*names) -> Dict[str, str]:
result = {}
with ContextDockerClient() as docker_client:
for name in names:
result[name] = docker_client.containers.get(name).id
return result


class RunDBTestDockerDBReuseTest(unittest.TestCase):

def setUp(self):
print(f"SetUp {self.__class__.__name__}")
self.test_environment = exaslct_utils.ExaslctTestEnvironmentWithCleanUp(self, exaslct_utils.EXASLCT_DEFAULT_BIN)
self._test_container_name = f"test_container_{self.test_environment.flavor_path.name}_release"
self._db_container_name = f"db_container_{self.test_environment.flavor_path.name}_release"
self.test_environment.clean_images()
self.remove_docker_container()

def tearDown(self):
self.remove_docker_container()
self.test_environment.close()

def remove_docker_container(self):
remove_docker_container([self._test_container_name, self._db_container_name])

def test_reuse(self):
def run_command():
command = [f"{self.test_environment.executable}",
f"run-db-test",
f"{exaslct_utils.get_full_test_container_folder_parameter()}",
"--reuse-test-environment"]
self.test_environment.run_command(" ".join(command), track_task_dependencies=True)

def container_ids() -> Dict[str, str]:
return get_docker_container_ids(
self._test_container_name,
self._db_container_name,
)

run_command()
old_ids = container_ids()
run_command()
new_ids = container_ids()
self.assertEqual(old_ids, new_ids)


if __name__ == '__main__':
unittest.main()

0 comments on commit 5d408ce

Please sign in to comment.