summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2023-06-18 12:25:19 +0200
committerHelmut Grohne <helmut@subdivi.de>2023-06-18 18:25:25 +0200
commit7c20ce632e6f50c8c64708fb9b0d335feba095d6 (patch)
tree5979ce78646dfe77e23ea37176f56188fed08acb
parent253347e6177fa86bad32dd919f1768e5c2d6f96c (diff)
downloadwsgitools-7c20ce632e6f50c8c64708fb9b0d335feba095d6.tar.gz
add testcase for scgi.asynchronous and fix reusesocket
-rwxr-xr-xtest.py32
-rw-r--r--wsgitools/scgi/asynchronous.py2
2 files changed, 34 insertions, 0 deletions
diff --git a/test.py b/test.py
index 1c7260a..fe6545f 100755
--- a/test.py
+++ b/test.py
@@ -411,6 +411,37 @@ class GzipWSGIFilterTest(unittest.TestCase):
data = gzip.GzipFile(fileobj=io.BytesIO(res.get_data())).read()
self.assertEqual(data, b"nothing")
+from wsgitools.scgi.asynchronous import SCGIServer as SCGIAsynchronousServer
+import asyncore
+import socket
+import threading
+
+class ScgiAsynchronousTest(unittest.TestCase):
+ def testSimple(self):
+ app = applications.StaticContent(
+ "200 OK", [("Content-Type", "text/plain")], b"nothing"
+ )
+ sock = socket.socket()
+ sock.bind(("localhost", 0))
+ sock.listen(5)
+ port = sock.getsockname()[1]
+ SCGIAsynchronousServer(app, port, reusesocket=sock)
+ serverthread = threading.Thread(
+ target=asyncore.loop, kwargs={"count": 10, "timeout": 0.01}
+ )
+ serverthread.start()
+ client = socket.socket()
+ client.connect(("localhost", port))
+ req = {"CONTENT_LENGTH": "0", "REQUEST_METHOD": "GET"}
+ reqb = str2bytes("".join(map("%s\0%s\0".__mod__, req.items())))
+ client.send(b"%d:%s," % (len(reqb), reqb))
+ data = client.recv(65536)
+ client.close()
+ self.assertTrue(data.startswith(b"Status: 200 OK\r\n"))
+ self.assertTrue(data.endswith(b"\r\n\r\nnothing"))
+ serverthread.join()
+ sock.close()
+
def alltests(case):
return unittest.TestLoader().loadTestsFromTestCase(case)
@@ -425,6 +456,7 @@ fullsuite.addTest(alltests(BasicAuthMiddlewareTest))
fullsuite.addTest(alltests(NoWriteCallableMiddlewareTest))
fullsuite.addTest(alltests(RequestLogWSGIFilterTest))
fullsuite.addTest(alltests(GzipWSGIFilterTest))
+fullsuite.addTest(alltests(ScgiAsynchronousTest))
if __name__ == "__main__":
runner = unittest.TextTestRunner(verbosity=2)
diff --git a/wsgitools/scgi/asynchronous.py b/wsgitools/scgi/asynchronous.py
index 5354ced..0b014bf 100644
--- a/wsgitools/scgi/asynchronous.py
+++ b/wsgitools/scgi/asynchronous.py
@@ -255,6 +255,8 @@ class SCGIServer(asyncore.dispatcher):
self.set_reuse_addr()
self.bind((interface, port))
self.listen(5)
+ else:
+ self.accepting = True
def handle_accept(self):
"""asyncore interface"""