diff --git a/CHANGELOG.md b/CHANGELOG.md index a3fb12b079a2227fdc463dab05e588d54ae3d706..4a9528d7afa0847464c0d75e522977eeba046631 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added (for new features) +* Tests for [linkahead-pylib#127](https://gitlab.com/linkahead/linkahead-pylib/-/issues/127) * Tests for [linkahead-server#280](https://gitlab.com/linkahead/linkahead-server/-/issues/280) * Test for [caosdb-pylib#119](https://gitlab.com/linkahead/linkahead-pylib/-/issues/119) * Test for [caosdb-pylib#89](https://gitlab.com/linkahead/linkahead-pylib/-/issues/89) diff --git a/tests/test_issues_pylib.py b/tests/test_issues_pylib.py index 32b2bdb2e1e5a8bf514e27517f7edff6767e219b..76641e98c265444145e0e8fd9ed328fe1d79dfdc 100644 --- a/tests/test_issues_pylib.py +++ b/tests/test_issues_pylib.py @@ -29,6 +29,7 @@ import os import tempfile import time import warnings +from pathlib import Path import linkahead as db import linkahead.common.utils @@ -196,3 +197,50 @@ def test_gitlab_com_120(): rt1_retrieved.update() # The update and addition of a new property must not change this, either. assert len(rt1_retrieved.get_property(rt2.name).properties) == 0 + + +def test_gitlab_com_127(): + """ + Test that the timeout option in pylinkahead.ini accepts separate + connect/read timeouts and timeout None. + + See https://gitlab.com/linkahead/linkahead-pylib/-/issues/127 and + https://gitlab.indiscale.com/caosdb/customers/f-fit/management/-/issues/93 + """ + # Find test profile config + test_profile_path = Path(__file__).parent.parent/'test_profile' + pylinkahead_paths = list(test_profile_path.rglob('.pylinkahead.ini')) + if len(pylinkahead_paths) != 1: + pytest.fail("Could not find correct config path") + pylinkahead_path = pylinkahead_paths[0] + temp_pylinkahead_path = pylinkahead_paths[0].parent/'.pyla-temp-test.ini' + temp_pylinkahead_path.unlink(True) + # Filter test profile content + pylinkahead_content = [] + with open(pylinkahead_path, "r") as pylinkahead: + for line in pylinkahead: + if not 'timeout' in line: + pylinkahead_content.append(line) + + # Parse various timeout strings and check successful connect + valid_timeout_strings = ["timeout = None", "timeout=null", + "timeout = (4, 40)", "timeout=(4,4)"] + for timeout_string in valid_timeout_strings: + try: + # Create temporary config with timeout option + with open(temp_pylinkahead_path, "x") as temp_pylinkahead: + for line in pylinkahead_content: + temp_pylinkahead.write(line) + temp_pylinkahead.write(timeout_string) + # Parse temporary config and check successful connect + db.get_config().read(str(temp_pylinkahead_path)) + db.configure_connection() + assert 'Connection to' in str(db.Info()) + finally: + # Delete temporary config + temp_pylinkahead_path.unlink() + + # Reset configuration + db.get_config().remove_option('Connection', 'timeout') + db.get_config().read(str(pylinkahead_path)) + db.configure_connection()