summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"""