-
Notifications
You must be signed in to change notification settings - Fork 88
feat(integration-tests): Add fixtures and tests for starting and stopping CLP 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
Changes from all commits
8e75e15
44ee20e
bbe0575
5cd47f8
c5375eb
2be837f
bf14b5e
27b7f5b
e041f0e
75672fc
0822a79
2df9515
63f3ae4
0011447
0ff9465
cdcfaee
53e7343
796ffe3
bae12de
9c9ef74
0f3dcd5
f9865a8
865e9ed
09d5200
5fffc32
571f313
e348be0
30f186f
e5da7e9
292ec70
0c4cfa4
bee738a
49eaf97
e3c4a3b
4cd92e6
87c4809
baddcfe
7cf597d
8372a9f
b92ee22
f950df0
aac6fcb
9f995b9
03cb974
0e0567a
d44ab95
324ade4
e7e79e1
7116cfc
3471168
a324248
6caf53a
f3e533d
a71bcb0
b5cf248
b496025
86ab692
ce822d8
8224985
cc1e5d1
7c2897f
a3ff51b
1176381
649d0b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| """Make the fixtures defined in `tests/fixtures/` globally available without imports.""" | ||
| """Global pytest setup.""" | ||
|
|
||
| # Make the fixtures defined in `tests/fixtures/` globally available without imports. | ||
| pytest_plugins = [ | ||
| "tests.fixtures.integration_test_logs", | ||
| "tests.fixtures.path_configs", | ||
| "tests.fixtures.package_instance", | ||
| "tests.fixtures.package_config", | ||
| ] |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||
| """Fixtures that create and remove temporary config files for CLP packages.""" | ||||||
quinntaylormitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| from collections.abc import Iterator | ||||||
|
|
||||||
| import pytest | ||||||
|
|
||||||
| from tests.utils.clp_mode_utils import get_clp_config_from_mode | ||||||
| from tests.utils.config import PackageConfig, PackagePathConfig | ||||||
|
|
||||||
|
|
||||||
| @pytest.fixture | ||||||
| def fixt_package_config( | ||||||
| request: pytest.FixtureRequest, | ||||||
| fixt_package_path_config: PackagePathConfig, | ||||||
| ) -> Iterator[PackageConfig]: | ||||||
| """ | ||||||
| Creates and maintains a PackageConfig object for a specific CLP mode. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename all references of "mode" to "flavour"? that's the terms we use in the docs: clp/docs/src/dev-docs/building-package.md Lines 41 to 42 in e6d7a58
unless we plan to add more modes to extend the differences beyond flavour variants?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @quinntaylormitchell do we plan to address this as the very last item? the rest of the code lgtm already
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apologies that I missed this @junhaoliao! I was trying out the new GitHub UI and I think it didn't show me the comment or something. We do plan to add more modes to extend the differences beyond flavour variants (e.g., |
||||||
|
|
||||||
| :param request: | ||||||
| :return: An iterator that yields the PackageConfig object for the specified mode. | ||||||
| """ | ||||||
| mode_name: str = request.param | ||||||
|
|
||||||
| # Get the ClpConfig for this mode. | ||||||
| clp_config_obj = get_clp_config_from_mode(mode_name) | ||||||
|
|
||||||
| # Construct PackageConfig. | ||||||
| package_config = PackageConfig( | ||||||
| path_config=fixt_package_path_config, | ||||||
| mode_name=mode_name, | ||||||
| clp_config=clp_config_obj, | ||||||
| ) | ||||||
|
|
||||||
| try: | ||||||
| yield package_config | ||||||
| finally: | ||||||
| package_config.temp_config_file_path.unlink(missing_ok=True) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """Fixtures that start and stop CLP package instances for integration tests.""" | ||
quinntaylormitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def fixt_package_instance(fixt_package_config: PackageConfig) -> Iterator[PackageInstance]: | ||
| """ | ||
| Starts a CLP package instance for the given configuration and stops it during teardown. | ||
|
|
||
| :param fixt_package_config: | ||
| :return: Iterator that yields the running package instance. | ||
| """ | ||
| mode_name = fixt_package_config.mode_name | ||
|
|
||
| try: | ||
| start_clp_package(fixt_package_config) | ||
| instance = PackageInstance(package_config=fixt_package_config) | ||
| yield instance | ||
| except RuntimeError: | ||
| pytest.fail(f"Failed to start the {mode_name} package.") | ||
| finally: | ||
| stop_clp_package(fixt_package_config) | ||
quinntaylormitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Integration tests verifying that the CLP package can be started and stopped.""" | ||
|
|
||
| import logging | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.utils.clp_mode_utils import CLP_MODE_CONFIGS | ||
| from tests.utils.config import PackageInstance | ||
|
|
||
| TEST_MODES = CLP_MODE_CONFIGS.keys() | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @pytest.mark.package | ||
| @pytest.mark.parametrize("fixt_package_config", TEST_MODES, indirect=True) | ||
| def test_clp_package(fixt_package_instance: PackageInstance) -> None: | ||
| """ | ||
| Validate that the CLP package starts up successfully for the selected mode(s) of operation. | ||
|
|
||
| :param fixt_package_instance: | ||
| """ | ||
| # TODO: write code that properly validates that the package is running. This is a placeholder. | ||
| mode_name = fixt_package_instance.package_config.mode_name | ||
| logger.info("The '%s' package has been spun up successfully.", mode_name) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """Provides utilities related to the user-level configurations of CLP's operating modes.""" | ||
|
|
||
| from collections.abc import Callable | ||
|
|
||
| from clp_py_utils.clp_config import ( | ||
| ClpConfig, | ||
| Package, | ||
| QueryEngine, | ||
| StorageEngine, | ||
| ) | ||
|
|
||
| CLP_MODE_CONFIGS: dict[str, Callable[[], ClpConfig]] = { | ||
| "clp-text": lambda: ClpConfig( | ||
quinntaylormitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| package=Package( | ||
| storage_engine=StorageEngine.CLP, | ||
| query_engine=QueryEngine.CLP, | ||
| ), | ||
| api_server=None, | ||
| ), | ||
| "clp-json": lambda: ClpConfig( | ||
| package=Package( | ||
| storage_engine=StorageEngine.CLP_S, | ||
| query_engine=QueryEngine.CLP_S, | ||
| ), | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| def get_clp_config_from_mode(mode_name: str) -> ClpConfig: | ||
| """ | ||
| Return a ClpConfig object for the given mode name. | ||
|
|
||
| :param mode_name: | ||
| :return: ClpConfig object corresponding to the mode. | ||
| :raise ValueError: If the mode is not supported. | ||
| """ | ||
| if mode_name not in CLP_MODE_CONFIGS: | ||
| err_msg = f"Unsupported mode: {mode_name}" | ||
| raise ValueError(err_msg) | ||
| return CLP_MODE_CONFIGS[mode_name]() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """Provides utility functions related to the CLP package used across `integration-tests`.""" | ||
|
|
||
| from tests.utils.asserting_utils import run_and_assert | ||
| from tests.utils.config import PackageConfig | ||
|
|
||
| DEFAULT_CMD_TIMEOUT_SECONDS = 120.0 | ||
|
|
||
|
|
||
| def start_clp_package(package_config: PackageConfig) -> None: | ||
| """ | ||
| Starts an instance of the CLP package. | ||
|
|
||
| :param package_config: | ||
| :raise: Propagates `run_and_assert`'s errors. | ||
| """ | ||
| path_config = package_config.path_config | ||
| start_script_path = path_config.start_script_path | ||
| temp_config_file_path = package_config.temp_config_file_path | ||
|
|
||
| # fmt: off | ||
| start_cmd = [ | ||
| str(start_script_path), | ||
| "--config", str(temp_config_file_path), | ||
| ] | ||
| # fmt: on | ||
| run_and_assert(start_cmd, timeout=DEFAULT_CMD_TIMEOUT_SECONDS) | ||
|
|
||
|
|
||
| def stop_clp_package(package_config: PackageConfig) -> None: | ||
| """ | ||
| Stops the running instance of the CLP package. | ||
|
|
||
| :param package_config: | ||
| :raise: Propagates `run_and_assert`'s errors. | ||
| """ | ||
| path_config = package_config.path_config | ||
| stop_script_path = path_config.stop_script_path | ||
| temp_config_file_path = package_config.temp_config_file_path | ||
|
|
||
| # fmt: off | ||
| stop_cmd = [ | ||
| str(stop_script_path), | ||
| "--config", str(temp_config_file_path), | ||
| ] | ||
| # fmt: on | ||
| run_and_assert(stop_cmd, timeout=DEFAULT_CMD_TIMEOUT_SECONDS) |
Uh oh!
There was an error while loading. Please reload this page.