A test for bootstrapping, have problem with test_tcpconnection ):

This commit is contained in:
Dmitri Bogomolov 2019-07-29 14:19:18 +03:00
parent bdb09c2d00
commit bcb29facaa
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
1 changed files with 43 additions and 5 deletions

View File

@ -13,9 +13,11 @@ import unittest
import knownnodes
import state
from bmconfigparser import BMConfigParser
from helper_msgcoding import MsgEncode, MsgDecode
from network import asyncore_pollchoose as asyncore
from network.tcp import TCPConnection
from network.connectionpool import BMConnectionPool
from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection
from queues import excQueue
knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat')
@ -80,8 +82,10 @@ class TestCore(unittest.TestCase):
' with no subject!' % e
@unittest.skip('Bad environment for asyncore.loop')
def test_tcpconnection(self):
"""initial fill script from network.tcp"""
BMConfigParser().set('bitmessagesettings', 'dontconnect', 'true')
for peer in (state.Peer("", 8448),):
direct = TCPConnection(peer)
@ -91,10 +95,18 @@ class TestCore(unittest.TestCase):
self.fail('Exception in test loop')
def _wipe_knownnodes(self):
def _wipe_knownnodes():
with knownnodes.knownNodesLock:
knownnodes.knownNodes = {stream: {} for stream in range(1, 4)}
def _outdate_knownnodes():
with knownnodes.knownNodesLock:
for nodes in knownnodes.knownNodes.itervalues():
for node in nodes.itervalues():
node['lastseen'] -= 2419205 # older than 28 days
def test_knownnodes_pickle(self):
"""ensure that 3 nodes was imported for each stream"""
@ -117,9 +129,7 @@ class TestCore(unittest.TestCase):
def test_0_cleaner(self):
"""test knownnodes starvation leading to IndexError in Asyncore"""
for nodes in knownnodes.knownNodes.itervalues():
for node in nodes.itervalues():
node['lastseen'] -= 2419205 # older than 28 days
# time.sleep(303) # singleCleaner wakes up every 5 min
while True:
@ -130,6 +140,34 @@ class TestCore(unittest.TestCase):
if thread == 'Asyncore' and isinstance(exc, IndexError):
self.fail("IndexError because of empty knownNodes!")
def test_bootstrap(self):
"""test bootstrapping"""
BMConfigParser().set('bitmessagesettings', 'dontconnect', 'true')
# it's weird, knownnodes appear empty
knownnodes.addKnownNode(1, state.Peer('', 8444), is_self=True)
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
proxy_type = BMConfigParser().safeGet(
'bitmessagesettings', 'socksproxytype')
if proxy_type == 'SOCKS5':
connection_base = Socks5BMConnection
elif proxy_type == 'SOCKS4a':
connection_base = Socks4aBMConnection
connection_base = TCPConnection
_started = time.time()
for _ in range(180):
for peer, con in BMConnectionPool().outboundConnections.iteritems():
if not peer.host.startswith('bootstrap'):
self.assertIsInstance(con, connection_base)
else: # pylint: disable=useless-else-on-loop
'Failed to connect during %s sec' % (time.time() - _started))
def run():
"""Starts all tests defined in this module"""