Commit ee3269f6 authored by Alexander Meißner's avatar Alexander Meißner

Merge branch 'auto-restart' into 'master'

auto restart server when crashed

See merge request sre18/break-it!11
parents 57c3602a 2a93fd00
Pipeline #6618 passed with stage
in 6 minutes and 4 seconds
......@@ -9,8 +9,18 @@ class BaseTest(unittest.TestCase):
self.client = None
def setUp(self):
self.client = self.test_server.create_client()
self.assertResponse(220)
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,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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment