update repository references and improve script handling

This commit is contained in:
2025-03-19 20:36:36 +01:00
parent 51b0252b0e
commit 1d90749486
160 changed files with 14361 additions and 18 deletions

View File

@@ -0,0 +1,46 @@
import asyncio
import pytest
from backup.worker import StopWorkException, Worker
from .faketime import FakeTime
@pytest.mark.asyncio
async def test_worker(time: FakeTime):
data = {'count': 0}
async def work():
if data['count'] >= 5:
raise StopWorkException()
data['count'] += 1
worker = Worker("test", work, time, 1)
task = await worker.start()
await asyncio.wait([task])
assert not worker.isRunning()
assert data['count'] == 5
assert time.sleeps == [1, 1, 1, 1, 1]
# assert worker._task.name == "test"
assert worker.getLastError() is None
@pytest.mark.asyncio
async def test_worker_error(time: FakeTime):
data = {'count': 0}
async def work():
if data['count'] >= 5:
raise StopWorkException()
data['count'] += 1
raise OSError()
worker = Worker("test", work, time, 1)
task = await worker.start()
await asyncio.wait([task])
assert not worker.isRunning()
assert data['count'] == 5
assert time.sleeps == [1, 1, 1, 1, 1]
# assert worker.getName() == "test"
assert worker.getLastError() is not None
assert type(worker.getLastError()) is OSError