diff --git a/onionr/apiservers/private/__init__.py b/onionr/apiservers/private/__init__.py index d6e63537..ca7587df 100644 --- a/onionr/apiservers/private/__init__.py +++ b/onionr/apiservers/private/__init__.py @@ -83,7 +83,7 @@ class PrivateAPI: except TypeError: return False - def getUptime(self): + def getUptime(self)->int: while True: try: return epoch.get_epoch() - self.startTime diff --git a/onionr/communicatorutils/daemonqueuehandler.py b/onionr/communicatorutils/daemonqueuehandler.py index 0cd881fb..0936c0df 100755 --- a/onionr/communicatorutils/daemonqueuehandler.py +++ b/onionr/communicatorutils/daemonqueuehandler.py @@ -30,6 +30,8 @@ def handle_daemon_commands(comm_inst): events.event('daemon_command', data = {'cmd' : cmd}) if cmd[0] == 'shutdown': comm_inst.shutdown = True + elif cmd[0] == 'runtimeTest': + comm_inst.shared_state.get_by_string("OnionrRunTestManager").run_tests() elif cmd[0] == 'remove_from_insert_list': try: comm_inst.generating_blocks.remove(cmd[1]) diff --git a/onionr/onionrcommands/daemonlaunch.py b/onionr/onionrcommands/daemonlaunch.py index 12d5fda1..797860e1 100755 --- a/onionr/onionrcommands/daemonlaunch.py +++ b/onionr/onionrcommands/daemonlaunch.py @@ -34,6 +34,7 @@ from onionrcrypto import getourkeypair from utils import hastor, logoheader from . import version import serializeddata +import runtests def _proper_shutdown(): localcommand.local_command('shutdown') @@ -52,12 +53,16 @@ def daemon(): logger.debug('Runcheck file found on daemon start, deleting in advance.') os.remove(filepaths.run_check_file) - # Create shared object + # Create shared objects shared_state = toomanyobjs.TooMany() Thread(target=shared_state.get(apiservers.ClientAPI).start, daemon=True, name='client HTTP API').start() Thread(target=shared_state.get(apiservers.PublicAPI).start, daemon=True, name='public HTTP API').start() + + # Init run time tester (ensures Onionr is running right, for testing purposes) + + shared_state.get(runtests.OnionrRunTestManager) shared_state.get(serializeddata.SerializedData) shared_state.share_object() # share the parent object to the threads diff --git a/onionr/onionrcommands/parser/arguments.py b/onionr/onionrcommands/parser/arguments.py index ae2dcbcc..341ea058 100644 --- a/onionr/onionrcommands/parser/arguments.py +++ b/onionr/onionrcommands/parser/arguments.py @@ -27,6 +27,7 @@ from .. import resettor # commands to reset the tor data directory or transport from .. import resetplugins # command to reinstall default plugins from .. import softreset # command to delete onionr blocks from .. import restartonionr # command to restart Onionr +from .. import runtimetestcmd import onionrexceptions from onionrutils import importnewblocks # func to import new blocks from onionrplugins import onionrevents as events @@ -54,7 +55,8 @@ def get_arguments()->dict: ('resettor', 'reset-tor'): resettor.reset_tor, ('resetplugins', 'reset-plugins'): resetplugins.reset, ('reset-tor-node-transport',): resettor.reset_tor_key_pair, - ('soft-reset', 'softreset'): softreset.soft_reset + ('soft-reset', 'softreset'): softreset.soft_reset, + ('runtime-test', 'runtimetest'): runtimetestcmd.do_runtime_test } return args diff --git a/onionr/onionrcommands/runtimetestcmd.py b/onionr/onionrcommands/runtimetestcmd.py new file mode 100644 index 00000000..412b7d64 --- /dev/null +++ b/onionr/onionrcommands/runtimetestcmd.py @@ -0,0 +1,6 @@ +from coredb import daemonqueue + +def do_runtime_test(): + daemonqueue.daemon_queue_add("runtimeTest") + +do_runtime_test.onionr_help = "If Onionr is running, initialize run time tests (check logs)" diff --git a/onionr/runtests/__init__.py b/onionr/runtests/__init__.py new file mode 100644 index 00000000..abc42f78 --- /dev/null +++ b/onionr/runtests/__init__.py @@ -0,0 +1,42 @@ +""" + Onionr - Private P2P Communication + + Test Onionr as it is running +""" +""" + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" +import logger +from onionrutils import epoch + +from . import uicheck + +RUN_TESTS = [uicheck.check_ui] + +class OnionrRunTestManager: + def __init__(self): + self.success:bool = True + self.run_date:int = 0 + + def run_tests(self): + cur_time = epoch.get_epoch() + logger.info(f"Doing runtime tests at {cur_time}") + try: + for i in RUN_TESTS: + last = i + i(self) + logger.info(last.__name__ + " passed") + except AssertionError: + logger.error(last.__name__ + ' failed') + \ No newline at end of file diff --git a/onionr/runtests/uicheck.py b/onionr/runtests/uicheck.py new file mode 100644 index 00000000..883f847d --- /dev/null +++ b/onionr/runtests/uicheck.py @@ -0,0 +1,3 @@ +from onionrutils import localcommand +def check_ui(test_manager): + if not 'onionr' in localcommand.local_command('/mail/').lower(): raise AssertionError \ No newline at end of file