Commit cc023eac authored by Łukasz Nowak's avatar Łukasz Nowak

caddy-frontend: Make test server serving in threads

Since haproxy checks the test server for availability and does it
asynchronously, the test server has to reply ASAP for given request, but when
one request blocks, then whole server is blocked, so just simply switch it to
threading model.

It's not the best, but good enough for test usage.
parent 482463e4
......@@ -37,6 +37,7 @@ from unittest import skip
import ssl
from BaseHTTPServer import HTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn
import time
import tempfile
import ipaddress
......@@ -198,6 +199,10 @@ def createCSR(common_name, ip=None):
return key, key_pem, csr, csr_pem
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
pass
class CertificateAuthority(object):
def __init__(self, common_name):
self.key, self.key_pem = createKey()
......@@ -599,11 +604,11 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
@classmethod
def startServerProcess(cls):
server = HTTPServer(
server = ThreadedHTTPServer(
(cls._ipv4_address, cls._server_http_port),
TestHandler)
server_https = HTTPServer(
server_https = ThreadedHTTPServer(
(cls._ipv4_address, cls._server_https_port),
TestHandler)
......@@ -655,7 +660,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
class OwnTestHandler(TestHandler):
identification = 'Auth Backend'
server_https_auth = HTTPServer(
server_https_auth = ThreadedHTTPServer(
(self._ipv4_address, self._server_https_auth_port),
OwnTestHandler)
......@@ -7139,14 +7144,14 @@ backend _health-check-default-http
if __name__ == '__main__':
class HTTP6Server(HTTPServer):
class HTTP6Server(ThreadedHTTPServer):
address_family = socket.AF_INET6
ip, port = sys.argv[1], int(sys.argv[2])
if ':' in ip:
klass = HTTP6Server
url_template = 'http://[%s]:%s/'
else:
klass = HTTPServer
klass = ThreadedHTTPServer
url_template = 'http://%s:%s/'
server = klass((ip, port), TestHandler)
......
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