Skip to content

Commit 133cafa

Browse files
committed
added autobahn test server support
1 parent 30ae919 commit 133cafa

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/autobahn_test_servers.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def run_cherrypy_server(host="127.0.0.1", port=9000):
99

1010
cherrypy.config.update({'server.socket_host': host,
1111
'server.socket_port': port,
12+
'engine.autoreload_on': False,
1213
'log.screen': False})
1314
WebSocketPlugin(cherrypy.engine).subscribe()
1415
cherrypy.tools.websocket = WebSocketTool()
@@ -55,7 +56,26 @@ def on_message(self, message):
5556
logger.warning("Serving Tornado server on %s:%s" % (host, port))
5657
ioloop.IOLoop.instance().start()
5758

59+
def run_autobahn_server(host="127.0.0.1", port=9003):
60+
from autobahntestsuite import choosereactor
61+
import autobahn
62+
from autobahn.websocket import listenWS
63+
from twisted.internet import reactor
64+
from autobahn.websocket import WebSocketServerFactory, \
65+
WebSocketServerProtocol
5866

67+
class ServerProtocol(WebSocketServerProtocol):
68+
def onMessage(self, msg, binary):
69+
self.sendMessage(msg, binary)
70+
71+
class ServerFactory(WebSocketServerFactory):
72+
protocol = ServerProtocol
73+
74+
factory = ServerFactory("ws://%s:%d" % (host, port))
75+
factory.setProtocolOptions(failByDrop=False)
76+
logger.warning("Serving Autobahn server on %s:%s" % (host, port))
77+
listenWS(factory, None)
78+
reactor.run()
5979

6080
if __name__ == '__main__':
6181
import argparse
@@ -74,12 +94,15 @@ def on_message(self, message):
7494
help='Run the gevent server backend')
7595
parser.add_argument('--run-tornado-server', dest='run_tornado', action='store_true',
7696
help='Run the Tornado server backend')
97+
parser.add_argument('--run-autobahn-server', dest='run_autobahn', action='store_true',
98+
help='Run the Autobahn server backend')
7799
args = parser.parse_args()
78100

79101
if args.run_all:
80102
args.run_cherrypy = True
81103
args.run_gevent = True
82104
args.run_tornado = True
105+
args.run_autobahn = True
83106

84107
procs = []
85108
logger.warning("CherryPy server: %s" % args.run_cherrypy)
@@ -100,6 +123,12 @@ def on_message(self, message):
100123
p2.daemon = True
101124
procs.append(p2)
102125

126+
logger.warning("Autobahn server: %s" % args.run_autobahn)
127+
if args.run_autobahn:
128+
p3 = Process(target=run_autobahn_server)
129+
p3.daemon = True
130+
procs.append(p3)
131+
103132
for p in procs:
104133
p.start()
105134
logging.info("Starting process... %d" % p.pid)

0 commit comments

Comments
 (0)