fix online peers having zero division error, added stress test insertion

master
Kevin Froman 2019-10-19 03:47:24 -05:00
parent b3ee096e49
commit e0c53ee118
6 changed files with 39 additions and 7 deletions

View File

@ -25,6 +25,9 @@
import locale import locale
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
ran_as_script = False
if __name__ == "__main__": ran_as_script = True
# Import standard libraries # Import standard libraries
import sys import sys
@ -33,6 +36,7 @@ import sys
try: try:
from urllib3.contrib.socks import SOCKSProxyManager from urllib3.contrib.socks import SOCKSProxyManager
except ModuleNotFoundError: except ModuleNotFoundError:
# check here or else we get error when onionr runs with tor
raise ModuleNotFoundError("You need the PySocks module (for use with socks5 proxy to use Tor)") raise ModuleNotFoundError("You need the PySocks module (for use with socks5 proxy to use Tor)")
# Onionr imports # Onionr imports
@ -58,7 +62,7 @@ def onionr_main():
parser.register() parser.register()
return return
if __name__ == "__main__": if ran_as_script:
onionr_main() onionr_main()
# Cleanup standard out/err because Python refuses to do it itsself # Cleanup standard out/err because Python refuses to do it itsself

View File

@ -67,8 +67,18 @@ class BlockUploadSessionManager:
comm_inst: OnionrCommunicatorDaemon = self._too_many.get_by_string("OnionrCommunicatorDaemon") comm_inst: OnionrCommunicatorDaemon = self._too_many.get_by_string("OnionrCommunicatorDaemon")
sessions_to_delete = [] sessions_to_delete = []
if comm_inst.getUptime() < 120: return if comm_inst.getUptime() < 120: return
onlinePeerCount = len(comm_inst.onlinePeers)
# If we have no online peers right now,
if onlinePeerCount == 0: return
for session in self.sessions: for session in self.sessions:
if (session.total_success_count / len(comm_inst.onlinePeers)) >= onionrvalues.MIN_BLOCK_UPLOAD_PEER_PERCENT: # if over 50% of peers that were online for a session have become unavailable, don't kill sessions
if session.total_success_count > onlinePeerCount:
if onlinePeerCount / session.total_success_count >= 0.5: return
# Clean sessions if they have uploaded to enough online peers
if session.total_success_count <= 0: continue
if (session.total_success_count / onlinePeerCount) >= onionrvalues.MIN_BLOCK_UPLOAD_PEER_PERCENT:
sessions_to_delete.append(session) sessions_to_delete.append(session)
for session in sessions_to_delete: for session in sessions_to_delete:
self.sessions.remove(session) self.sessions.remove(session)

View File

@ -20,9 +20,9 @@
import logger import logger
from onionrutils import epoch from onionrutils import epoch
from . import uicheck, inserttest from . import uicheck, inserttest, stresstest
RUN_TESTS = [uicheck.check_ui, inserttest.insert_bin_test] RUN_TESTS = [uicheck.check_ui, inserttest.insert_bin_test, stresstest.stress_test_block_insert]
class OnionrRunTestManager: class OnionrRunTestManager:
def __init__(self): def __init__(self):

View File

@ -1,11 +1,13 @@
import os import os
import time
import onionrblocks import onionrblocks
import logger import logger
import coredb import coredb
from communicator import peeraction
def _check_remote_node(testmanager): def _check_remote_node(testmanager):
return return
def insert_bin_test(testmanager): def insert_bin_test(testmanager):
data = os.urandom(32) data = os.urandom(32)

View File

@ -0,0 +1,16 @@
import os
import onionrblocks
import logger
import coredb
from onionrutils import epoch
def stress_test_block_insert(testmanager):
start = epoch.get_epoch()
count = 100
max_insert_speed = 120
for x in range(count): onionrblocks.insert(os.urandom(32))
speed = epoch.get_epoch() - start
if speed < max_insert_speed:
raise ValueError(f'{count} blocks inserted too fast, {max_insert_speed}, got {speed}')
logger.info(f'runtest stress block insertion: {count} blocks inserted in {speed}s')

View File

@ -5,5 +5,5 @@ def check_ui(test_manager):
result = localcommand.local_command(point) result = localcommand.local_command(point)
if not result: raise ValueError if not result: raise ValueError
result = result.lower() result = result.lower()
if not 'onionr' in result and not 'Onionr' in result: if not 'script' in result:
raise ValueError raise ValueError(f'uicheck failed on {point}')