fix online peers having zero division error, added stress test insertion
parent
b3ee096e49
commit
e0c53ee118
|
@ -25,6 +25,9 @@
|
|||
import locale
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
ran_as_script = False
|
||||
if __name__ == "__main__": ran_as_script = True
|
||||
|
||||
# Import standard libraries
|
||||
import sys
|
||||
|
||||
|
@ -33,6 +36,7 @@ import sys
|
|||
try:
|
||||
from urllib3.contrib.socks import SOCKSProxyManager
|
||||
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)")
|
||||
|
||||
# Onionr imports
|
||||
|
@ -58,7 +62,7 @@ def onionr_main():
|
|||
parser.register()
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
if ran_as_script:
|
||||
onionr_main()
|
||||
|
||||
# Cleanup standard out/err because Python refuses to do it itsself
|
||||
|
|
|
@ -67,8 +67,18 @@ class BlockUploadSessionManager:
|
|||
comm_inst: OnionrCommunicatorDaemon = self._too_many.get_by_string("OnionrCommunicatorDaemon")
|
||||
sessions_to_delete = []
|
||||
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:
|
||||
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)
|
||||
for session in sessions_to_delete:
|
||||
self.sessions.remove(session)
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
import logger
|
||||
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:
|
||||
def __init__(self):
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import os
|
||||
import time
|
||||
|
||||
import onionrblocks
|
||||
import logger
|
||||
import coredb
|
||||
from communicator import peeraction
|
||||
|
||||
def _check_remote_node(testmanager):
|
||||
return
|
||||
|
|
|
@ -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')
|
|
@ -5,5 +5,5 @@ def check_ui(test_manager):
|
|||
result = localcommand.local_command(point)
|
||||
if not result: raise ValueError
|
||||
result = result.lower()
|
||||
if not 'onionr' in result and not 'Onionr' in result:
|
||||
raise ValueError
|
||||
if not 'script' in result:
|
||||
raise ValueError(f'uicheck failed on {point}')
|
||||
|
|
Loading…
Reference in New Issue