From 713296c5206da5c9287ff4d6b7507b6baa9f71c7 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 12 Jul 2023 12:27:55 +0000 Subject: [PATCH] test(backups): make delay settable per dummyservice --- .../services/test_service/__init__.py | 17 +++++++++++------ tests/test_services.py | 5 +++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/selfprivacy_api/services/test_service/__init__.py b/selfprivacy_api/services/test_service/__init__.py index da4960a..07b460b 100644 --- a/selfprivacy_api/services/test_service/__init__.py +++ b/selfprivacy_api/services/test_service/__init__.py @@ -23,6 +23,7 @@ class DummyService(Service): """A test service""" folders: List[str] = [] + startstop_delay = 0 def __init_subclass__(cls, folders: List[str]): cls.folders = folders @@ -119,19 +120,23 @@ class DummyService(Service): pass @classmethod - def stop(cls, delay=DEFAULT_DELAY): + def set_delay(cls, new_delay): + cls.startstop_delay = new_delay + + @classmethod + def stop(cls): cls.set_status(ServiceStatus.DEACTIVATING) - cls.change_status_with_async_delay(ServiceStatus.INACTIVE, delay) + cls.change_status_with_async_delay(ServiceStatus.INACTIVE, cls.startstop_delay) @classmethod - def start(cls, delay=DEFAULT_DELAY): + def start(cls): cls.set_status(ServiceStatus.ACTIVATING) - cls.change_status_with_async_delay(ServiceStatus.ACTIVE, delay) + cls.change_status_with_async_delay(ServiceStatus.ACTIVE, cls.startstop_delay) @classmethod - def restart(cls, delay=DEFAULT_DELAY): + def restart(cls): cls.set_status(ServiceStatus.RELOADING) # is a correct one? - cls.change_status_with_async_delay(ServiceStatus.ACTIVE, delay) + cls.change_status_with_async_delay(ServiceStatus.ACTIVE, cls.startstop_delay) @staticmethod def get_configuration(): diff --git a/tests/test_services.py b/tests/test_services.py index 4d4c8f4..12889c3 100644 --- a/tests/test_services.py +++ b/tests/test_services.py @@ -30,13 +30,14 @@ def test_unimplemented_folders_raises(): def test_delayed_start_stop(raw_dummy_service): dummy = raw_dummy_service + dummy.set_delay(0.3) - dummy.stop(delay=0.3) + dummy.stop() assert dummy.get_status() == ServiceStatus.DEACTIVATING wait_until_true(lambda: dummy.get_status() == ServiceStatus.INACTIVE) assert dummy.get_status() == ServiceStatus.INACTIVE - dummy.start(delay=0.3) + dummy.start() assert dummy.get_status() == ServiceStatus.ACTIVATING wait_until_true(lambda: dummy.get_status() == ServiceStatus.ACTIVE) assert dummy.get_status() == ServiceStatus.ACTIVE