Commit 1d871c10 authored by Łukasz Nowak's avatar Łukasz Nowak

test: Randomize ports on each run

parent 2ec3c141
......@@ -35,6 +35,7 @@ import tempfile
import time
import unittest
import zc.lockfile
import socket
from cryptography import x509
from cryptography.hazmat.backends import default_backend
......@@ -50,6 +51,15 @@ import cli
import updater
def findFreeTCPPort(ip=''):
"""Find a free TCP port to listen to.
"""
family = socket.AF_INET6 if ':' in ip else socket.AF_INET
with contextlib.closing(socket.socket(family, socket.SOCK_STREAM)) as s:
s.bind((ip, 0))
return str(s.getsockname()[1])
@contextlib.contextmanager
def captured_output():
new_out, new_err = StringIO.StringIO(), StringIO.StringIO()
......@@ -136,7 +146,8 @@ class KedifaMixinCaucase(KedifaMixin):
self.pem = certificate_pem + key_pem
def setUpCaucase(self):
ip, port = os.environ['SLAPOS_TEST_IPV6'], 15080
ip, port = os.environ['SLAPOS_TEST_IPV6'],\
findFreeTCPPort(os.environ['SLAPOS_TEST_IPV6'])
self.caucased = os.path.join(self.testdir, 'caucased')
caucase_db = os.path.join(self.caucased, 'caucase.sqlite')
self.caucase_service = os.path.join(self.testdir, 'service')
......@@ -215,7 +226,7 @@ class KedifaMixinCaucase(KedifaMixin):
def setUpKedifa(self, ip):
self.db = os.path.join(self.testdir, 'pocket.sqlite')
self.pidfile = os.path.join(self.testdir, 'kedifa.pid')
port = '16080'
port = findFreeTCPPort(ip)
self.kedifa_runtime = multiprocessing.Process(
target=cli.http,
args=(
......
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