added offset test for lan block list and improved run time tests to be random order and have better iterative output

This commit is contained in:
Kevin Froman 2020-03-21 01:14:35 -05:00
parent 05ea54cd28
commit 4696e7be3f
2 changed files with 27 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import os
import logger import logger
from onionrutils import epoch from onionrutils import epoch
from onionrcrypto.cryptoutils.randomshuffle import random_shuffle
from . import uicheck, inserttest, stresstest from . import uicheck, inserttest, stresstest
from . import ownnode from . import ownnode
@ -50,6 +51,7 @@ class OnionrRunTestManager:
self.run_date: int = 0 self.run_date: int = 0
def run_tests(self): def run_tests(self):
tests = random_shuffle(RUN_TESTS)
cur_time = epoch.get_epoch() cur_time = epoch.get_epoch()
logger.info(f"Doing runtime tests at {cur_time}") logger.info(f"Doing runtime tests at {cur_time}")
@ -58,13 +60,18 @@ class OnionrRunTestManager:
except FileNotFoundError: except FileNotFoundError:
pass pass
done_count: int = 0
total_to_do: int = len(tests)
try: try:
for i in RUN_TESTS: for i in tests:
last = i last = i
logger.info("[RUNTIME TEST] " + last.__name__ + " started", logger.info("[RUNTIME TEST] " + last.__name__ + " started",
terminal=True, timestamp=True) terminal=True, timestamp=True)
i(self) i(self)
logger.info("[RUNTIME TEST] " + last.__name__ + " passed", done_count += 1
logger.info("[RUNTIME TEST] " + last.__name__ +
f" passed {done_count}/{total_to_do}",
terminal=True, timestamp=True) terminal=True, timestamp=True)
except (ValueError, AttributeError): except (ValueError, AttributeError):
logger.error(last.__name__ + ' failed assertions', terminal=True) logger.error(last.__name__ + ' failed assertions', terminal=True)

View File

@ -3,20 +3,34 @@ import requests
from lan.getip import best_ip from lan.getip import best_ip
from onionrblocks import insert, onionrblockapi from onionrblocks import insert, onionrblockapi
from gevent import sleep
from coredb import blockmetadb
from onionrutils.epoch import get_epoch
import logger
def test_lan_server(testmanager): def test_lan_server(testmanager):
start_time = get_epoch()
for i in range(1024, 65536): for i in range(1024, 65536):
try: try:
if requests.get(f"http://{best_ip}:{i}/ping").text == 'pong!': if requests.get(f"http://{best_ip}:{i}/ping").text == 'pong!':
bl = insert('test data') bl = insert('test data')
sleep(10)
bl2 = insert('test data2') bl2 = insert('test data2')
l = requests.get(f"http://{best_ip}:{i}/blist/0").text sleep(30)
if bl not in l or bl2 not in l: bl3 = insert('test data3')
l = requests.get(f"http://{best_ip}:{i}/blist/0").text.split('\n')
if bl not in l or bl2 not in l or bl3 not in l:
logger.error('blocks not in blist ' + '-'.join(l), terminal=True)
raise ValueError
time = blockmetadb.get_block_date(bl3) - 1
l = requests.get(f"http://{best_ip}:{i}/blist/{time}").text.split('\n')
if (bl in l and bl2 in l and bl3 in l) or len(l) == 0:
logger.error('Failed to get appopriate time' + '-'.join(l), terminal=True)
raise ValueError raise ValueError
if onionrblockapi.Block(bl).raw != requests.get(f"http://{best_ip}:{i}/get/{bl}").content: if onionrblockapi.Block(bl).raw != requests.get(f"http://{best_ip}:{i}/get/{bl}").content:
raise ValueError raise ValueError
break break
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError: