dcache/tests/runner.py

66 lines
1.9 KiB
Python
Raw Normal View History

2023-12-31 01:19:53 +05:30
#!/bin/env /usr/bin/python3
# Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
2023-12-31 01:28:59 +05:30
#
2023-12-31 01:19:53 +05:30
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2023-12-31 01:28:59 +05:30
#
2023-12-31 01:19:53 +05:30
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
2023-12-31 01:28:59 +05:30
#
2023-12-31 01:19:53 +05:30
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from threading import Thread
import asyncio
import importlib.util
import sys
2023-12-31 01:28:59 +05:30
sys.path.append("/home/atm/code/mcaptcha/dcache/")
2023-12-31 01:19:53 +05:30
import bucket
import mcaptcha
import result
import pow
2023-12-31 01:28:59 +05:30
2023-12-31 01:19:53 +05:30
class Runner(object):
__fn = [
bucket.incr_one_works,
bucket.race_works,
bucket.difficulty_works,
mcaptcha.delete_captcha_works,
mcaptcha.captcha_exists_works,
mcaptcha.register_captcha_works,
mcaptcha.rename_captcha_works,
result.add_result_works,
result.result_doesnt_exist,
result.result_ttl_works,
result.delete_result_works,
pow.add_pow_works,
pow.pow_doesnt_exist,
pow.pow_ttl_works,
pow.delete_pow_works,
]
__tasks = []
async def __register(self):
2023-12-31 01:28:59 +05:30
"""Register functions to be run"""
2023-12-31 01:19:53 +05:30
for fn in self.__fn:
task = asyncio.create_task(fn())
self.__tasks.append(task)
async def run(self):
"""Wait for registered functions to finish executing"""
await self.__register()
for task in self.__tasks:
await task
"""Runs in separate threads"""
2023-12-31 01:28:59 +05:30
2023-12-31 01:19:53 +05:30
def __init__(self):
super(Runner, self).__init__()