-
Notifications
You must be signed in to change notification settings - Fork 83
feat(integration-tests): Test the startup and teardown of the clp-text and clp-json packages.
#1437
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
Open
quinntaylormitchell
wants to merge
27
commits into
y-scope:main
Choose a base branch
from
quinntaylormitchell:testing-start-stop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8e75e15
Test a generic clp package start up and spin down (default: clp-text).
quinntaylormitchell 44ee20e
Merge branch 'main' into feature branch
quinntaylormitchell bbe0575
Expand to clp-text and clp-json; store JSON config pairs in temp conf…
quinntaylormitchell 5cd47f8
Merge branch 'main' into feature branch
quinntaylormitchell c5375eb
Include and employ clp_py_utils.clp_config; refrain from using the us…
quinntaylormitchell 2be837f
Lint.
quinntaylormitchell bf14b5e
Refactor; move all utility functions to utils files as appropriate.
quinntaylormitchell 27b7f5b
Add comments.
quinntaylormitchell e041f0e
Streamline logger calls.
quinntaylormitchell 75672fc
Deduplicate fixture code.
quinntaylormitchell 0822a79
Merge branch 'main' into feature branch
quinntaylormitchell 2df9515
Change method of clp_config import; temporary, will change again once…
quinntaylormitchell 63f3ae4
Generalize code so that it's better equipped to handle future CLP_MOD…
quinntaylormitchell 0011447
Merge branch 'main' into feature branch
quinntaylormitchell 0ff9465
Combine PackageConfig, PackageModeConfig, and PackageInstanceConfig i…
quinntaylormitchell cdcfaee
Employ a 'CLPConfig'-centric approach rather than 'dict'-centric.
quinntaylormitchell 53e7343
Store list of required components for each mode
quinntaylormitchell 796ffe3
Generalize the method by which the mode of operation is determined.
quinntaylormitchell bae12de
Move all mode-related utilities to their own file.
quinntaylormitchell 9c9ef74
Minor error.
quinntaylormitchell 0f3dcd5
Move load_yaml_to_dict to general utilities file.
quinntaylormitchell f9865a8
Add taskfile tasks for package tests.
quinntaylormitchell 865e9ed
Address rabbit comments.
quinntaylormitchell 09d5200
Add mariadb_config install for linting purposes (will be unecessary a…
quinntaylormitchell 5fffc32
Lint YAML.
quinntaylormitchell 571f313
Merge branch 'main' into feature branch
quinntaylormitchell e348be0
Adapt code after #1549 merge.
quinntaylormitchell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
integration-tests/tests/fixtures/package_config_fixtures.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Fixtures that create and remove temporary config files for CLP packages.""" | ||
|
|
||
| import logging | ||
| from collections.abc import Iterator | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.utils.config import PackageConfig | ||
| from tests.utils.package_utils import ( | ||
| CLP_MODE_CONFIGS, | ||
| write_temp_config_file, | ||
| ) | ||
| from tests.utils.utils import get_env_var | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _build_package_config_for_mode(mode_name: str) -> PackageConfig: | ||
| """Construct a PackageConfig for the given `mode_name`.""" | ||
| if mode_name not in CLP_MODE_CONFIGS: | ||
| err_msg = f"Unknown CLP mode '{mode_name}'." | ||
| raise KeyError(err_msg) | ||
|
|
||
| clp_package_dir = Path(get_env_var("CLP_PACKAGE_DIR")).expanduser().resolve() | ||
| test_root_dir = Path(get_env_var("CLP_BUILD_DIR")).expanduser().resolve() / "integration-tests" | ||
|
|
||
| build_config = CLP_MODE_CONFIGS[mode_name][0] | ||
| required_components = CLP_MODE_CONFIGS[mode_name][1] | ||
| package_config = PackageConfig( | ||
| clp_package_dir=clp_package_dir, | ||
| test_root_dir=test_root_dir, | ||
| mode_name=mode_name, | ||
| build_config=build_config, | ||
| component_list=required_components, | ||
| ) | ||
|
|
||
| # Write the temporary config file that the package will use. | ||
| clp_config_obj = build_config() | ||
| temp_config_file_path: Path = write_temp_config_file( | ||
| clp_config=clp_config_obj, | ||
| temp_config_dir=package_config.temp_config_dir, | ||
| mode_name=mode_name, | ||
| ) | ||
| object.__setattr__(package_config, "temp_config_file_path", temp_config_file_path) | ||
|
|
||
| return package_config | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def clp_config( | ||
| request: pytest.FixtureRequest, | ||
| ) -> Iterator[PackageConfig]: | ||
| """ | ||
| Parameterized fixture that creates and maintains a PackageConfig object for a specific mode of | ||
| operation. | ||
| """ | ||
| mode_name: str = request.param | ||
| logger.info("Creating a temporary config file for the %s package...", mode_name) | ||
|
|
||
| package_config = _build_package_config_for_mode(mode_name) | ||
|
|
||
| logger.info("The temporary config file has been written for the %s package.", mode_name) | ||
|
|
||
| try: | ||
| yield package_config | ||
| finally: | ||
| logger.info("Removing the temporary config file...") | ||
| package_config.temp_config_file_path.unlink() | ||
quinntaylormitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger.info("The temporary config file has been removed.") | ||
50 changes: 50 additions & 0 deletions
50
integration-tests/tests/fixtures/package_instance_fixtures.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """Fixtures that start and stop CLP package instances for integration tests.""" | ||
|
|
||
| import logging | ||
| import subprocess | ||
| from collections.abc import Iterator | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.utils.config import ( | ||
| PackageConfig, | ||
| PackageInstance, | ||
| ) | ||
| from tests.utils.package_utils import ( | ||
| start_clp_package, | ||
| stop_clp_package, | ||
| ) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def clp_package( | ||
| clp_config: PackageConfig, | ||
| ) -> Iterator[PackageInstance]: | ||
| """ | ||
| Parameterized fixture that starts a instance of the CLP package in the configuration described | ||
| in PackageConfig, and gracefully stops it at teardown. | ||
| """ | ||
| mode_name = clp_config.mode_name | ||
| logger.info("Starting up the %s package...", mode_name) | ||
|
|
||
| start_clp_package(clp_config) | ||
|
|
||
| try: | ||
| instance = PackageInstance(package_config=clp_config) | ||
| instance_id = instance.clp_instance_id | ||
| logger.info( | ||
| "An instance of the %s package was started successfully. Its instance ID is '%s'", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
| yield instance | ||
| finally: | ||
| logger.info("Now stopping the %s package...", mode_name) | ||
| if instance is not None: | ||
| stop_clp_package(instance) | ||
| else: | ||
| # This means setup failed after start; fall back to calling stop script directly | ||
| subprocess.run([str(clp_config.stop_script_path)], check=True) | ||
| logger.info("The %s package was stopped successfully.", mode_name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Integration tests verifying that the CLP package can be started and stopped.""" | ||
|
|
||
| import logging | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.utils.config import PackageInstance | ||
| from tests.utils.package_utils import ( | ||
| CLP_MODE_CONFIGS, | ||
| is_package_running, | ||
| is_running_mode_correct, | ||
| ) | ||
|
|
||
| TEST_MODES = CLP_MODE_CONFIGS.keys() | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @pytest.mark.package | ||
| @pytest.mark.parametrize("clp_config", TEST_MODES, indirect=True) | ||
| def test_clp_package(clp_package: PackageInstance) -> None: | ||
| """ | ||
| Validate that all of the components of the CLP package start up successfully for the selected | ||
| mode of operation. | ||
| """ | ||
| # Spin up the package by getting the PackageInstance fixture. | ||
| package_instance = clp_package | ||
| mode_name = package_instance.package_config.mode_name | ||
| instance_id = package_instance.clp_instance_id | ||
|
|
||
| # Ensure that all package components are running. | ||
| logger.info( | ||
| "Checking if all components of %s package with instance ID '%s' are running properly...", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
|
|
||
| running, fail_msg = is_package_running(package_instance) | ||
| if not running: | ||
| assert fail_msg is not None | ||
| pytest.fail(fail_msg) | ||
quinntaylormitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info( | ||
| "All components of the %s package with instance ID '%s' are running properly.", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
|
|
||
| # Ensure that the package is running in the correct mode. | ||
| logger.info( | ||
| "Checking that the %s package with instance ID '%s' is running in the correct mode...", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
|
|
||
| correct, fail_msg = is_running_mode_correct(package_instance) | ||
| if not correct: | ||
| assert fail_msg is not None | ||
| pytest.fail(fail_msg) | ||
|
|
||
| logger.info( | ||
| "The %s package with instance ID '%s' is running in the correct mode.", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just curious. Are there tests that will result in status other than the default pass/fail?
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.
I don't think so; I just added this so that there is a test summary that shows up when all the tests that the user requested have finished running. is there a better way to do that?