From af45785d506e8f8e32fd26d3d671621630bc2cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Safin?= Date: Sat, 13 Jul 2024 23:53:17 +0200 Subject: [PATCH 1/2] test_setup_runtime_arguments_parametrized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Safin --- tests/test_main.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index 62df2fa..c69394f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -158,3 +158,36 @@ def test_quit(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr(main, "exit_event", exit_mock) main.quit(1, None) exit_mock.set.assert_called_once() + + +@pytest.mark.parametrize( + "cli_args,expected_attributes", + [ + (["main.py", "--single"], {"single": True}), + (["main.py", "--debug-notifications"], {"debug_notifications": True}), + ( + ["main.py", "--debug-download", "example.log"], + {"debug_download": "example.log"}, + ), + (["main.py", "--list"], {"list": True}), + (["main.py", "--restore-latest"], {"restore_latest": True}), + (["main.py", "--target", "example_target"], {"target": "example_target"}), + ( + ["main.py", "--restore", "example_restore"], + {"restore": "example_restore"}, + ), + ], +) +def test_setup_runtime_arguments_parametrized( + monkeypatch: pytest.MonkeyPatch, + cli_args: list[str], + expected_attributes: dict[str, bool | str], +) -> None: + monkeypatch.setattr("sys.argv", cli_args) + + args: main.RuntimeArgs = main.setup_runtime_arguments() + + assert isinstance(args, main.RuntimeArgs) + + for attribute, expected_value in expected_attributes.items(): + assert getattr(args, attribute) == expected_value From 0dd9a4447d3ddb6fe34cc7f390f58dd0efebef83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Safin?= Date: Sat, 13 Jul 2024 23:59:29 +0200 Subject: [PATCH 2/2] adjust SIGTERM_TIMEOUT_SECS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Safin --- docs/configuration.md | 2 +- ogion/config.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 0ae44c4..f520aed 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -32,7 +32,7 @@ Environemt variables | SUBPROCESS_TIMEOUT_SECS | int | Indicates how long subprocesses can last. Note that all backups are run from shell in subprocesses. Defaults to 3600 seconds which should be enough for even big dbs to make backup of. Min `5` and max `86400` (24h). | 3600 | | ZIP_ARCHIVE_LEVEL | int | Compression level of 7-zip via `-mx` option: `-mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)`. Defaults to `3` which should be sufficient and fast enough. Min `1` and max `9`. | 3 | | LOG_FOLDER_PATH | string | Path to store log files, for local development `./logs`, in container `/var/log/ogion`. | /var/log/ogion | -| SIGTERM_TIMEOUT_SECS | int | Time in seconds on exit how long ogion will wait for ongoing backup threads before force killing them and exiting. Min `0` and max `86400` (24h). | 30 | +| SIGTERM_TIMEOUT_SECS | int | Time in seconds on exit how long ogion will wait for ongoing backup threads before force killing them and exiting. Min `0` and max `86400` (24h). | 3600 | | ZIP_SKIP_INTEGRITY_CHECK | bool | By default set to `false` and after 7zip archive is created, integrity check runs on it. You can opt out this behaviour for performance reasons, use `true`. | false | | OGION_CPU_ARCHITECTURE | string | CPU architecture, supported `amd64` and `arm64`. Docker container will set it automatically so probably do not change it. | amd64 | diff --git a/ogion/config.py b/ogion/config.py index 5bde7ff..f0d5864 100644 --- a/ogion/config.py +++ b/ogion/config.py @@ -56,7 +56,7 @@ class Settings(BaseSettings): default="amd64", alias_priority=2, alias="OGION_CPU_ARCHITECTURE" ) SUBPROCESS_TIMEOUT_SECS: float = Field(ge=5, le=3600 * 24, default=3600) - SIGTERM_TIMEOUT_SECS: float = Field(ge=0, le=3600 * 24, default=30) + SIGTERM_TIMEOUT_SECS: float = Field(ge=0, le=3600 * 24, default=3600) ZIP_ARCHIVE_LEVEL: int = Field(ge=1, le=9, default=3) BACKUP_MAX_NUMBER: int = Field(ge=1, le=998, default=7) BACKUP_MIN_RETENTION_DAYS: int = Field(ge=0, le=36600, default=3)