Commit 2a93fd00 authored by Leonard Marschke's avatar Leonard Marschke 👾
Browse files

auto restart server when crashed

parent b8cca557
Loading
Loading
Loading
Loading
Loading
+10 −0
Changes for util/BaseTest.py: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,8 +9,18 @@ class BaseTest(unittest.TestCase):
        self.client = None

    def setUp(self):
        for i in range(0, 2):
            try:
                self.client = self.test_server.create_client()
                self.assertResponse(220)
                return
            except (ConnectionRefusedError, self.failureException) as exception:
                if i == 1:
                    raise exception

                # Did you try to turn it off and on again?
                self.test_server.stop()
                self.test_server.start()

    def tearDown(self):
        self.client.close()
+16 −2
Changes for util/TestServer.py: 16 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,13 @@ class TestServer:
        self.docker_port = docker_port
        self.docker_id = None
        self.ssl_on = ssl_on
        self.wait_up = wait_up
        self.start()

    def start(self):
        if self.docker_id:
            raise AssertionError('Docker id already set')

        # pylint: disable=unsubscriptable-object
        self.docker_id = subprocess.check_output(['docker',
                                                  'run',
@@ -24,10 +31,17 @@ class TestServer:
                                                  '-p',
                                                  '{}:{}'.format(self.port, self.docker_port),
                                                  self.container_template])[:-1]
        time.sleep(wait_up)
        time.sleep(self.wait_up)

    def stop(self):
        if not self.docker_id:
            raise AssertionError('No docker ID set!')

        subprocess.run(['docker', 'kill', self.docker_id], stdout=subprocess.PIPE)
        self.docker_id = None

    def cleanup(self):
        subprocess.check_output(['docker', 'kill', self.docker_id])
        return self.stop()

    def create_client(self):
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)