Skip to content

Commit

Permalink
A separate test for connection to bootstrap servers
Browse files Browse the repository at this point in the history
  • Loading branch information
g1itch committed Jan 22, 2021
1 parent 7b8bf08 commit d9d1cdb
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/tests/core.py
Expand Up @@ -8,6 +8,7 @@
import Queue
import random # nosec
import shutil
import socket
import string
import sys
import time
Expand Down Expand Up @@ -163,7 +164,12 @@ def _initiate_bootstrap(self):
knownnodes.cleanupKnownNodes()
time.sleep(2)

def _check_bootstrap(self):
def _check_connection(self):
"""
Check if there is at least one outbound connection to remote host
with name not starting with "bootstrap" in 3 minutes,
fail otherwise.
"""
_started = time.time()
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
proxy_type = BMConfigParser().safeGet(
Expand All @@ -184,18 +190,33 @@ def _check_bootstrap(self):
self.fail(
'Failed to connect during %s sec' % (time.time() - _started))

def test_connection(self):
"""test connection to bootstrap servers"""
self._initiate_bootstrap()
for port in [8080, 8444]:
for item in socket.getaddrinfo(
'bootstrap%s.bitmessage.org' % port, 80):
try:
addr = item[4][0]
socket.inet_aton(item[4][0])
except (TypeError, socket.error):
continue
else:
knownnodes.addKnownNode(1, Peer(addr, port))
self._check_connection()

def test_bootstrap(self):
"""test bootstrapping"""
self._initiate_bootstrap()
self._check_bootstrap()
self._check_connection()

@unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test')
def test_bootstrap_tor(self):
"""test bootstrapping with tor"""
self._initiate_bootstrap()
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'stem')
start_proxyconfig()
self._check_bootstrap()
self._check_connection()

@unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test')
def test_onionservicesonly(self): # this should start after bootstrap
Expand Down

0 comments on commit d9d1cdb

Please sign in to comment.