Fix random failures of test_onionservicesonly() #1780
|
@ -119,6 +119,14 @@ class TestCore(unittest.TestCase):
|
||||||
except:
|
except:
|
||||||
self.fail('Exception in test loop')
|
self.fail('Exception in test loop')
|
||||||
|
|
||||||
|
def _load_knownnodes(self, filepath):
|
||||||
|
with knownnodes.knownNodesLock:
|
||||||
|
shutil.copyfile(filepath, knownnodes_file)
|
||||||
|
try:
|
||||||
|
knownnodes.readKnownNodes()
|
||||||
|
except AttributeError as e:
|
||||||
|
self.fail('Failed to load knownnodes: %s' % e)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _wipe_knownnodes():
|
def _wipe_knownnodes():
|
||||||
with knownnodes.knownNodesLock:
|
with knownnodes.knownNodesLock:
|
||||||
|
@ -245,6 +253,10 @@ class TestCore(unittest.TestCase):
|
||||||
self._initiate_bootstrap()
|
self._initiate_bootstrap()
|
||||||
self._check_connection()
|
self._check_connection()
|
||||||
self._check_knownnodes()
|
self._check_knownnodes()
|
||||||
|
# backup potentially enough knownnodes
|
||||||
|
knownnodes.saveKnownNodes()
|
||||||
|
with knownnodes.knownNodesLock:
|
||||||
|
shutil.copyfile(knownnodes_file, knownnodes_file + '.bak')
|
||||||
|
|
||||||
@unittest.skipIf(tor_port_free, 'no running tor detected')
|
@unittest.skipIf(tor_port_free, 'no running tor detected')
|
||||||
def test_bootstrap_tor(self):
|
def test_bootstrap_tor(self):
|
||||||
|
@ -261,7 +273,14 @@ class TestCore(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5')
|
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5')
|
||||||
BMConfigParser().set('bitmessagesettings', 'onionservicesonly', 'true')
|
BMConfigParser().set('bitmessagesettings', 'onionservicesonly', 'true')
|
||||||
self._initiate_bootstrap()
|
self._load_knownnodes(knownnodes_file + '.bak')
|
||||||
|
if len([
|
||||||
|
node for node in knownnodes.knownNodes[1]
|
||||||
|
if node.host.endswith('.onion')
|
||||||
|
]) < 3: # generate fake onion nodes if have not enough
|
||||||
|
with knownnodes.knownNodesLock:
|
||||||
|
for f in ('a', 'b', 'c', 'd'):
|
||||||
|
knownnodes.addKnownNode(1, Peer(f * 16 + '.onion', 8444))
|
||||||
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
|
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
|
||||||
tried_hosts = set()
|
tried_hosts = set()
|
||||||
for _ in range(360):
|
for _ in range(360):
|
||||||
|
@ -276,7 +295,7 @@ class TestCore(unittest.TestCase):
|
||||||
'connections!' % peer.host)
|
'connections!' % peer.host)
|
||||||
if len(tried_hosts) > 2:
|
if len(tried_hosts) > 2:
|
||||||
return
|
return
|
||||||
self.fail('Failed to connect to at least 3 nodes within 360 sec')
|
self.fail('Failed to find at least 3 nodes to connect within 360 sec')
|
||||||
|
|
||||||
def test_udp(self):
|
def test_udp(self):
|
||||||
"""check default udp setting and presence of Announcer thread"""
|
"""check default udp setting and presence of Announcer thread"""
|
||||||
|
@ -351,15 +370,14 @@ class TestCore(unittest.TestCase):
|
||||||
self.assertEqual(column_type[0][0] if column_type else '', 'text')
|
self.assertEqual(column_type[0][0] if column_type else '', 'text')
|
||||||
|
|
||||||
def test_old_knownnodes_pickle(self):
|
def test_old_knownnodes_pickle(self):
|
||||||
"""Testing old(v.0.6.2) version knownnodes.dat file"""
|
"""Testing old (v0.6.2) version knownnodes.dat file"""
|
||||||
try:
|
try:
|
||||||
old_source_file = os.path.join(
|
self._load_knownnodes(
|
||||||
os.path.abspath(os.path.dirname(__file__)), 'test_pattern', 'knownnodes.dat')
|
os.path.join(
|
||||||
new_destination_file = os.path.join(state.appdata, 'knownnodes.dat')
|
os.path.abspath(os.path.dirname(__file__)),
|
||||||
shutil.copyfile(old_source_file, new_destination_file)
|
'test_pattern', 'knownnodes.dat'))
|
||||||
knownnodes.readKnownNodes()
|
except self.failureException:
|
||||||
except AttributeError as e:
|
raise
|
||||||
self.fail('Failed to load knownnodes: %s' % e)
|
|
||||||
finally:
|
finally:
|
||||||
cleanup(files=('knownnodes.dat',))
|
cleanup(files=('knownnodes.dat',))
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user