Skip to content

Commit

Permalink
Add wsgiref server for autobahn test
Browse files Browse the repository at this point in the history
  • Loading branch information
bozzzzo committed Feb 4, 2016
1 parent c7e51fd commit f092a41
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
49 changes: 48 additions & 1 deletion test/autobahn_test_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,38 @@ def onMessage(self, payload, isBinary):

reactor.listenTCP(port, factory)
reactor.run()



def run_python_wsgi(host="127.0.0.1", port=9002):
"""
Runs wsgi server on python 2.x"
"""
run_python_wsgi_async(host, port, False)

def run_python_wsgi_async(host="127.0.0.1", port=9010, async=True):
"""
Runs wsgi server on python 2.x with async middleware"
"""

from wsgiref.simple_server import make_server
from ws4py.websocket import EchoWebSocket
from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler
from ws4py.server.wsgiutils import WebSocketWSGIApplication

app = WebSocketWSGIApplication(handler_cls=EchoWebSocket)
if async:
def middleware(app):
def later(environ, start_response):
for part in app(environ, start_response):
yield part
return later
app = middleware(app)
server = make_server(host, port, server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=app)
server.initialize_websockets_manager()
server.serve_forever()

if __name__ == '__main__':
import argparse
from multiprocessing import Process
Expand Down Expand Up @@ -162,6 +193,10 @@ def onMessage(self, payload, isBinary):
help='Run the Autobahn server backend')
parser.add_argument('--run-asyncio-server', dest='run_asyncio', action='store_true',
help='Run the asyncio server backend')
parser.add_argument('--run-wsgi-server', dest='run_wsgi', action='store_true',
help='Run the wsgi server backend')
parser.add_argument('--run-wsgi-async-server', dest='run_wsgi_async', action='store_true',
help='Run the wsgi server backend with an async middleware')
args = parser.parse_args()

if args.run_all:
Expand Down Expand Up @@ -221,6 +256,18 @@ def onMessage(self, payload, isBinary):
p7.daemon = True
procs.append(p7)

logger.warning("wsgi server: %s" % args.run_wsgi)
if args.run_wsgi:
p8 = Process(target=run_python_wsgi)
p8.daemon = True
procs.append(p8)

logger.warning("wsgi server async: %s" % args.run_wsgi_async)
if args.run_wsgi_async:
p9 = Process(target=run_python_wsgi_async)
p9.daemon = True
procs.append(p9)

for p in procs:
p.start()
logging.info("Starting process... %d" % p.pid)
Expand Down
8 changes: 8 additions & 0 deletions test/fuzzingclient.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@

{"agent": "ws4py (asyncio)/wsaccel for Python 3.4.0",
"url": "ws://127.0.0.1:9009/",
"options": {"version": 18}},

{"agent": "ws4py (wsgi) for Python 2.7",
"url": "ws://127.0.0.1:9002/",
"options": {"version": 18}},

{"agent": "ws4py (wsgi async) for Python 2.7",
"url": "ws://127.0.0.1:9010/",
"options": {"version": 18}}

],
Expand Down

0 comments on commit f092a41

Please sign in to comment.