added run time test framework
parent
6d2ae36f38
commit
f14239db6c
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)"
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
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')
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from onionrutils import localcommand
|
||||
def check_ui(test_manager):
|
||||
if not 'onionr' in localcommand.local_command('/mail/').lower(): raise AssertionError
|
Loading…
Reference in New Issue