From ae40447deb9646b23fa0828271e319aa0abe6bdc Mon Sep 17 00:00:00 2001
From: Alexander Schlemmer <alexander.schlemmer@ds.mpg.de>
Date: Wed, 28 Nov 2018 14:35:29 +0100
Subject: [PATCH] new make entry to run and keep a qunit test server

---
 makefile                      |  5 ++++-
 misc/unit_test_http_server.py | 13 ++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/makefile b/makefile
index ae1b2f90..4f47998c 100644
--- a/makefile
+++ b/makefile
@@ -49,7 +49,10 @@ PORT = 8000
 TIMEOUT = 200
 XVFB-RUN = xvfb-run -e /dev/stderr
 run-test-server: test
-	cd $(PUBLIC_DIR); $(MISC_DIR)/unit_test_http_server.py $(PORT) $(TIMEOUT); echo $$? > $(ROOT_DIR)/.server_done
+	cd $(PUBLIC_DIR); $(MISC_DIR)/unit_test_http_server.py $(PORT) $(TIMEOUT) False; echo $$? > $(ROOT_DIR)/.server_done
+
+keep-test-server:
+	cd $(PUBLIC_DIR); $(MISC_DIR)/unit_test_http_server.py $(PORT) $(TIMEOUT) True; echo $$? > $(ROOT_DIR)/.server_done
 
 run-qunit:
 	# start server
diff --git a/misc/unit_test_http_server.py b/misc/unit_test_http_server.py
index 02932298..80a46878 100755
--- a/misc/unit_test_http_server.py
+++ b/misc/unit_test_http_server.py
@@ -59,7 +59,11 @@ class UnitTestsHandler(SimpleHTTPRequestHandler):
         Shut down the server with an exit code which depends on the success of
         the unit test suite - If the tests succeeded the server exists with 0,
         otherwise with 1.
+
+        If the server has the ignore_done flag set this method immediately returns.
         """
+        if self.server.ignore_done:
+            return
         #pylint: disable=protected-access
         post_data = self.log()
         if "SUCCESS" in post_data:
@@ -85,15 +89,18 @@ class UnitTestHTTPServer(HTTPServer):
     A HTTP server which handles the request to the webcaosdb sources and the
     tests and servers as a logger when POST request are send to the `log`
     resource.
+
+    ignore_done: If set to true the server does not terminate on receiving a "/Done".
     """
 
-    def __init__(self, server_address, timeout):
+    def __init__(self, server_address, timeout, ignore_done):
         super(UnitTestHTTPServer, self).__init__(server_address,
                                                  UnitTestsHandler)
         self.timeout = timeout
+        self.ignore_done = ignore_done
         self._keep_running = True
         self._exit_message = None
-        self._exit_code = None
+        self._exit_code = None        
 
     def handle_timeout(self):
         """handle_timeout as defined in socketserver.BaseServer
@@ -122,4 +129,4 @@ class UnitTestHTTPServer(HTTPServer):
 
 
 UnitTestHTTPServer(server_address=('127.0.0.1', int(sys.argv[1])),
-                   timeout=float(sys.argv[2])).start()
+                   timeout=float(sys.argv[2]), ignore_done=(sys.argv[3]=="True")).start()
-- 
GitLab