test(backups): test jobs starting and finishing when from Backups

This commit is contained in:
Houkime 2023-04-24 17:03:56 +00:00
parent d340b0ca67
commit 396b42b69c
3 changed files with 9 additions and 2 deletions

View file

@ -207,6 +207,7 @@ class Backups:
Backups._store_last_snapshot(repo_name, snapshot) Backups._store_last_snapshot(repo_name, snapshot)
service.post_restore() service.post_restore()
Jobs.update(job, status=JobStatus.FINISHED)
@staticmethod @staticmethod
def init_repo(service: Service): def init_repo(service: Service):

View file

@ -23,10 +23,11 @@ def validate_datetime(dt: datetime):
# huey tasks need to return something # huey tasks need to return something
@huey.task() @huey.task()
def start_backup(service: Service) -> bool: def start_backup(service: Service) -> bool:
# Backups can create the job, but doing this here
# allows us to see the job as queued before it is actually executed
add_backup_job(service) add_backup_job(service)
Backups.back_up(service) Backups.back_up(service)
job = get_backup_job(service)
Jobs.update(job, status=JobStatus.FINISHED)
return True return True

View file

@ -131,7 +131,10 @@ def test_backup_simple_file(raw_dummy_service, file_backup):
def test_backup_service(dummy_service, backups): def test_backup_service(dummy_service, backups):
id = dummy_service.get_id()
assert_job_finished(f"services.{id}.backup", count=0)
assert Backups.get_last_backed_up(dummy_service) is None assert Backups.get_last_backed_up(dummy_service) is None
Backups.back_up(dummy_service) Backups.back_up(dummy_service)
now = datetime.now(timezone.utc) now = datetime.now(timezone.utc)
@ -140,6 +143,8 @@ def test_backup_service(dummy_service, backups):
assert now > date assert now > date
assert now - date < timedelta(minutes=1) assert now - date < timedelta(minutes=1)
assert_job_finished(f"services.{id}.backup", count=1)
def test_no_repo(memory_backup): def test_no_repo(memory_backup):
with pytest.raises(ValueError): with pytest.raises(ValueError):