test(backups): make delay settable per dummyservice

This commit is contained in:
Houkime 2023-07-12 12:27:55 +00:00
parent e7a6700522
commit 713296c520
2 changed files with 14 additions and 8 deletions

View file

@ -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():

View file

@ -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