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 ...@@ -37,6 +37,7 @@ from unittest import skip
import ssl import ssl
from BaseHTTPServer import HTTPServer from BaseHTTPServer import HTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler from BaseHTTPServer import BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn
import time import time
import tempfile import tempfile
import ipaddress import ipaddress
...@@ -198,6 +199,10 @@ def createCSR(common_name, ip=None): ...@@ -198,6 +199,10 @@ def createCSR(common_name, ip=None):
return key, key_pem, csr, csr_pem return key, key_pem, csr, csr_pem
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
pass
class CertificateAuthority(object): class CertificateAuthority(object):
def __init__(self, common_name): def __init__(self, common_name):
self.key, self.key_pem = createKey() self.key, self.key_pem = createKey()
...@@ -599,11 +604,11 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase): ...@@ -599,11 +604,11 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
@classmethod @classmethod
def startServerProcess(cls): def startServerProcess(cls):
server = HTTPServer( server = ThreadedHTTPServer(
(cls._ipv4_address, cls._server_http_port), (cls._ipv4_address, cls._server_http_port),
TestHandler) TestHandler)
server_https = HTTPServer( server_https = ThreadedHTTPServer(
(cls._ipv4_address, cls._server_https_port), (cls._ipv4_address, cls._server_https_port),
TestHandler) TestHandler)
...@@ -655,7 +660,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase): ...@@ -655,7 +660,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
class OwnTestHandler(TestHandler): class OwnTestHandler(TestHandler):
identification = 'Auth Backend' identification = 'Auth Backend'
server_https_auth = HTTPServer( server_https_auth = ThreadedHTTPServer(
(self._ipv4_address, self._server_https_auth_port), (self._ipv4_address, self._server_https_auth_port),
OwnTestHandler) OwnTestHandler)
...@@ -7139,14 +7144,14 @@ backend _health-check-default-http ...@@ -7139,14 +7144,14 @@ backend _health-check-default-http
if __name__ == '__main__': if __name__ == '__main__':
class HTTP6Server(HTTPServer): class HTTP6Server(ThreadedHTTPServer):
address_family = socket.AF_INET6 address_family = socket.AF_INET6
ip, port = sys.argv[1], int(sys.argv[2]) ip, port = sys.argv[1], int(sys.argv[2])
if ':' in ip: if ':' in ip:
klass = HTTP6Server klass = HTTP6Server
url_template = 'http://[%s]:%s/' url_template = 'http://[%s]:%s/'
else: else:
klass = HTTPServer klass = ThreadedHTTPServer
url_template = 'http://%s:%s/' url_template = 'http://%s:%s/'
server = klass((ip, port), TestHandler) server = klass((ip, port), TestHandler)
......
  • @luke I guess this is to fix 502 errors we sometimes see in the tests ( like here ), this is good !

  • Yes, those too, it got repetitive in more complex cases, thus I was able to fix it in proper place.

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