Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/tests/conftest.py
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
@pytest.fixture(scope='session') | @pytest.fixture(scope='session') | ||||
def swh_app(celery_session_app): | def swh_app(celery_session_app): | ||||
from swh.scheduler.celery_backend import config | from swh.scheduler.celery_backend import config | ||||
config.app = celery_session_app | config.app = celery_session_app | ||||
yield celery_session_app | yield celery_session_app | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_scheduler(postgresql): | def swh_scheduler_config(request, postgresql): | ||||
scheduler_config = { | scheduler_config = { | ||||
'db': postgresql.dsn, | 'db': postgresql.dsn, | ||||
} | } | ||||
all_dump_files = sorted(glob.glob(DUMP_FILES), key=sortkey) | all_dump_files = sorted(glob.glob(DUMP_FILES), key=sortkey) | ||||
cursor = postgresql.cursor() | cursor = postgresql.cursor() | ||||
for fname in all_dump_files: | for fname in all_dump_files: | ||||
with open(fname) as fobj: | with open(fname) as fobj: | ||||
cursor.execute(fobj.read()) | cursor.execute(fobj.read()) | ||||
postgresql.commit() | postgresql.commit() | ||||
scheduler = get_scheduler('local', scheduler_config) | return scheduler_config | ||||
@pytest.fixture | |||||
def swh_scheduler(swh_scheduler_config): | |||||
scheduler = get_scheduler('local', swh_scheduler_config) | |||||
for taskname in TASK_NAMES: | for taskname in TASK_NAMES: | ||||
scheduler.create_task_type({ | scheduler.create_task_type({ | ||||
'type': 'swh-test-{}'.format(taskname), | 'type': 'swh-test-{}'.format(taskname), | ||||
'description': 'The {} testing task'.format(taskname), | 'description': 'The {} testing task'.format(taskname), | ||||
'backend_name': 'swh.scheduler.tests.tasks.{}'.format(taskname), | 'backend_name': 'swh.scheduler.tests.tasks.{}'.format(taskname), | ||||
'default_interval': timedelta(days=1), | 'default_interval': timedelta(days=1), | ||||
'min_interval': timedelta(hours=6), | 'min_interval': timedelta(hours=6), | ||||
'max_interval': timedelta(days=12), | 'max_interval': timedelta(days=12), | ||||
}) | }) | ||||
return scheduler | return scheduler | ||||
# this alias is used to be able to easily instantiate a db-backed Scheduler | # this alias is used to be able to easily instantiate a db-backed Scheduler | ||||
# eg. for the RPC client/server test suite. | # eg. for the RPC client/server test suite. | ||||
swh_db_scheduler = swh_scheduler | swh_db_scheduler = swh_scheduler |