[qpid-dispatch] branch master updated: DISPATCH-1888: hack delays in http1 tests to allow socket cleanup

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[qpid-dispatch] branch master updated: DISPATCH-1888: hack delays in http1 tests to allow socket cleanup

kgiusti
This is an automated email from the ASF dual-hosted git repository.

kgiusti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/master by this push:
     new ab318d9  DISPATCH-1888: hack delays in http1 tests to allow socket cleanup
ab318d9 is described below

commit ab318d9e3b7b3fb7e57decdb97ac6b0ef7eb938d
Author: Kenneth Giusti <[hidden email]>
AuthorDate: Tue Jan 12 11:33:43 2021 -0500

    DISPATCH-1888: hack delays in http1 tests to allow socket cleanup
---
 tests/system_test.py                |  7 ++++++
 tests/system_tests_http1_adaptor.py | 45 ++++++++++++++++++++++++++-----------
 2 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/tests/system_test.py b/tests/system_test.py
index 5181492..a476016 100755
--- a/tests/system_test.py
+++ b/tests/system_test.py
@@ -994,6 +994,8 @@ class AsyncTestReceiver(MessagingHandler):
         self._thread.join(timeout=TIMEOUT)
         if self._thread.is_alive():
             raise Exception("AsyncTestReceiver did not exit")
+        del self._conn
+        del self._container
 
     def on_start(self, event):
         kwargs = {'url': self.address}
@@ -1055,6 +1057,8 @@ class AsyncTestSender(MessagingHandler):
         self.error = None
         self.link_stats = None
 
+        self._conn = None
+        self._sender = None
         self._message = message or Message(body="test")
         self._container = Container(self)
         cid = container_id or "ATS-%s:%s" % (target, uuid.uuid4())
@@ -1076,6 +1080,9 @@ class AsyncTestSender(MessagingHandler):
         assert not self._thread.is_alive(), "sender did not complete"
         if self.error:
             raise AsyncTestSender.TestSenderException(self.error)
+        del self._sender
+        del self._conn
+        del self._container
 
     def on_start(self, event):
         self._conn = self._container.connect(self.address)
diff --git a/tests/system_tests_http1_adaptor.py b/tests/system_tests_http1_adaptor.py
index 57979cc..c182a3d 100644
--- a/tests/system_tests_http1_adaptor.py
+++ b/tests/system_tests_http1_adaptor.py
@@ -226,6 +226,14 @@ class MyHTTPServer(HTTPServer):
         self.request_count = 0
         HTTPServer.__init__(self, addr, handler_cls)
 
+    def server_close(self):
+        try:
+            # force immediate close of listening socket
+            self.socket.shutdown(socket.SHUT_RDWR)
+        except Exception:
+            pass
+        HTTPServer.server_close(self)
+
 
 class TestServer(object):
     """
@@ -271,6 +279,8 @@ class TestServer(object):
         if self._server:
             self._server.server_close()
             self.request_count = self._server.request_count
+            del self._server
+        sleep(0.5)  # fudge factor allow socket close to complete
 
 
 class ThreadedTestClient(object):
@@ -335,6 +345,7 @@ class ThreadedTestClient(object):
     def wait(self, timeout=TIMEOUT):
         self._thread.join(timeout=TIMEOUT)
         self._logger.log("TestClient %s shut down" % self._conn_addr)
+        sleep(0.5)  # fudge factor allow socket close to complete
 
     def dump_log(self):
         self._logger.dump()
@@ -1432,25 +1443,26 @@ class Http1AdaptorEdge2EdgeTest(TestCase):
 
 
 class FakeHttpServerBase(object):
-    def __init__(self, host='', port=80):
+    """
+    A very base socket server to simulate HTTP server behaviors
+    """
+    def __init__(self, host='', port=80, bufsize=1024):
         super(FakeHttpServerBase, self).__init__()
         self.host = host
         self.port = port
-        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self.socket.settimeout(TIMEOUT)
-        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        self.socket.bind((host, port))
-        self.socket.listen(1)
-        self.conn, self.addr = self.socket.accept()
+        self.listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.listener.settimeout(TIMEOUT)
+        self.listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        self.listener.bind((host, port))
+        self.listener.listen(1)
+        self.conn, self.addr = self.listener.accept()
 
         self.do_connect()
         while True:
-            data = self.conn.recv(1024)
+            data = self.conn.recv(bufsize)
             if not data: break
             self.do_data(data)
-        self.do_closed()
-        self.conn.close()
-        self.socket.close()
+        self.do_close()
 
     def do_connect(self):
         pass
@@ -1458,8 +1470,14 @@ class FakeHttpServerBase(object):
     def do_data(self, data):
         pass
 
-    def do_closed(self):
-        pass
+    def do_close(self):
+        self.listener.shutdown(socket.SHUT_RDWR)
+        self.listener.close()
+        del self.listener
+        self.conn.shutdown(socket.SHUT_RDWR)
+        self.conn.close()
+        del self.conn
+        sleep(0.5)  # fudge factor allow socket close to complete
 
 
 class Http1AdaptorBadEndpointsTest(TestCase):
@@ -1678,6 +1696,7 @@ class Http1AdaptorBadEndpointsTest(TestCase):
         # self.assertIsNotNone(client.error)
 
         rx.stop()
+        sleep(0.5)  # fudge factor allow socket close to complete
 
         # verify router is still sane:
         count, error = http1_ping(self.http_server_port,


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]