mCaptcha-cache/tests/runner.py

57 lines
1.8 KiB
Python
Raw Normal View History

#!/bin/env /usr/bin/python3
2021-06-06 09:10:30 +03:00
# Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
#
# 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.
#
# 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.
#
# 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
2021-06-07 14:44:39 +03:00
import asyncio
2021-06-06 09:10:30 +03:00
2021-06-08 16:43:57 +03:00
import bucket
import mcaptcha
2021-06-09 16:06:31 +03:00
import challenge
2021-06-08 16:43:57 +03:00
2021-06-06 09:10:30 +03:00
class Runner(object):
2021-06-08 16:43:57 +03:00
__fn = [
bucket.incr_one_works,
bucket.race_works,
bucket.difficulty_works,
mcaptcha.delete_captcha_works,
mcaptcha.captcha_exists_works,
2021-06-09 16:06:31 +03:00
mcaptcha.register_captcha_works,
2021-07-19 13:51:48 +03:00
mcaptcha.rename_captcha_works,
2021-06-09 16:06:31 +03:00
challenge.add_challenge_works,
challenge.challenge_doesnt_exist,
challenge.challenge_ttl_works,
challenge.duplicate_challenge_works,
2021-06-10 15:57:27 +03:00
challenge.delete_challenge_works,
2021-06-08 16:43:57 +03:00
]
__tasks = []
2021-06-06 09:10:30 +03:00
2021-06-08 16:43:57 +03:00
async def __register(self):
2021-06-07 14:44:39 +03:00
""" Register functions to be run"""
2021-06-08 16:43:57 +03:00
for fn in self.__fn:
task = asyncio.create_task(fn())
self.__tasks.append(task)
2021-06-06 09:10:30 +03:00
2021-06-08 16:43:57 +03:00
async def run(self):
2021-06-07 14:44:39 +03:00
"""Wait for registered functions to finish executing"""
2021-06-08 16:43:57 +03:00
await self.__register()
for task in self.__tasks:
2021-06-07 14:44:39 +03:00
await task
2021-06-06 09:10:30 +03:00
2021-12-06 10:26:35 +03:00
"""Runs in separate threads"""
2021-06-06 09:10:30 +03:00
def __init__(self):
super(Runner, self).__init__()