diff --git a/minode/tests/test_process.py b/minode/tests/test_process.py index e5959fc..0eb462f 100644 --- a/minode/tests/test_process.py +++ b/minode/tests/test_process.py @@ -1,12 +1,18 @@ import unittest +import os +import shutil import signal import subprocess import sys import tempfile +import threading import time import psutil +from minode import shared +from minode.main import main as app + class TestProcessProto(unittest.TestCase): """Test process attributes, common flow""" @@ -18,18 +24,23 @@ class TestProcessProto(unittest.TestCase): home = None @classmethod - def setUpClass(cls): + def _build_app_args(cls, extra=None): if not cls.home: cls.home = tempfile.gettempdir() - cmd = cls._process_cmd + [ + args = cls._process_cmd + [ '--data-dir', cls.home, '--connection-limit', str(cls._connection_limit) ] if not cls._listen: - cmd += ['--no-incoming'] + args += ['--no-incoming'] elif cls._listening_port: - cmd += ['-p', str(cls._listening_port)] - cls.process = psutil.Popen(cmd, stderr=subprocess.STDOUT) # nosec + args += ['-p', str(cls._listening_port)] + + if extra: + args += extra + + print('ARGS: %r' % args) + return args @classmethod def _stop_process(cls, timeout=5): @@ -40,6 +51,11 @@ class TestProcessProto(unittest.TestCase): return False return True + @classmethod + def setUpClass(cls): + cmd = cls._build_app_args() + cls.process = psutil.Popen(cmd, stderr=subprocess.STDOUT) # nosec + @classmethod def tearDownClass(cls): """Ensures the process is stopped and removes files""" @@ -112,3 +128,41 @@ class TestProcess(TestProcessProto): else: if self._listen: self.fail('No listening connection found') + + +class TestConnectivity(TestProcessProto): + """Check connectivity between instances""" + _process_cmd = [ + 'minode', '--trusted-peer', '127.0.0.1:8445'] + # _listen = True + + @classmethod + def setUpClass(cls): + super(TestConnectivity, cls).setUpClass() + + cls._listen = True + cls._listening_port = 8445 + cls.home = os.path.join(cls.home, 'client') + os.mkdir(cls.home) + # sys.argv = cls._build_app_args(['--trusted-peer', '127.0.0.1:8444']) + cls._process_cmd = ['minode', '--no-outgoing'] + sys.argv = cls._build_app_args() + cls.app = threading.Thread(name="minode", target=app, daemon=True) + cls.app.start() + + @classmethod + def tearDownClass(cls): + super(TestConnectivity, cls).tearDownClass() + shared.shutting_down = True + shutil.rmtree(cls.home) + + def test_connections(self): + """Check the connection with trusted peer""" + time.sleep(5) + for t in range(10): + time.sleep(1) + connection_count = len([ + c for c in shared.connections.copy() + if c.status == 'fully_established']) + if connection_count != 1: + self.fail("Unexpected connection count: %i" % connection_count)