diff options
| author | LV-426 <lv-426@taproot.org.il> | 2015-01-20 03:00:41 +0200 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2015-01-20 04:00:42 +0200 |
| commit | ef1db057f27f7dc79c6145543451c3c3a62eba4d (patch) | |
| tree | 1e90e53a35ae05d4ea407ad2d21232e8c3cc6ea5 /src | |
| parent | 710cb02025448d6ec5207985ebcde915a9d2e8e0 (diff) | |
refactor rz_socket into top-level class
Diffstat (limited to 'src')
| -rw-r--r-- | src/server-tests/test_rz_mesh.py | 37 | ||||
| -rw-r--r-- | src/server/rz_mesh.py | 15 |
2 files changed, 26 insertions, 26 deletions
diff --git a/src/server-tests/test_rz_mesh.py b/src/server-tests/test_rz_mesh.py index b6743628..aa6c9778 100644 --- a/src/server-tests/test_rz_mesh.py +++ b/src/server-tests/test_rz_mesh.py @@ -12,6 +12,19 @@ from neo4j_util import generate_random_id__uuid from rz_api_websocket import WebSocket_Graph_NS import test_util +class RZ_websocket(object): + + def __init__(self, namespace=BaseNamespace): + self.namespace = namespace + + def __enter__(self): + sock = SocketIO('rhizi.local', 8080) + ns_sock = sock.define(self.namespace, '/graph') + self.sock = sock + return sock, ns_sock + + def __exit__(self, e_type, e_value, e_traceback): + self.sock.disconnect() class TestMeshAPI(unittest.TestCase): """ @@ -28,20 +41,6 @@ class TestMeshAPI(unittest.TestCase): def tearDownClass(cls): pass - class rz_socket: - - def __init__(self, namespace=BaseNamespace): - self.namespace = namespace - - def __enter__(self): - sock = SocketIO('rhizi.local', 8080) - ns_sock = sock.define(self.namespace, '/graph') - self.sock = sock - return sock, ns_sock - - def __exit__(self, e_type, e_value, e_traceback): - self.sock.disconnect() - def _emit_tx_topo_diff(self): with TestMeshAPI.rz_socket() as (_, ns_sock): n_set = [{'__label_set': ['xxx'], 'id': generate_random_id__uuid() }] @@ -63,7 +62,7 @@ class TestMeshAPI(unittest.TestCase): def c_0(): - with TestMeshAPI.rz_socket(namespace=NS_test) as (sock, _): + with RZ_websocket(namespace=NS_test) as (sock, _): c1_t.switch() # allow peer to POST sock.wait(8) # allow self to receive @@ -100,14 +99,14 @@ class TestMeshAPI(unittest.TestCase): topo_diff = Topo_Diff(node_set_add=[n_0, n_1], link_set_add=[l]) def c_0(): - with TestMeshAPI.rz_socket(namespace=NS_test) as (_, ns_sock): + with RZ_websocket(namespace=NS_test) as (_, ns_sock): c1_t.switch() # allow peer to connect data = json.dumps(topo_diff, cls=Topo_Diff.JSON_Encoder) ns_sock.emit('diff_commit__topo', data) c1_t.switch() def c_1(): - with TestMeshAPI.rz_socket(namespace=NS_test) as (sock, _): + with RZ_websocket(namespace=NS_test) as (sock, _): c0_t.switch() # allow peer to emit sock.wait(8) # allow self to receive @@ -143,14 +142,14 @@ class TestMeshAPI(unittest.TestCase): attr_diff.add_node_attr_rm(n_id, 'attr_2') def c_0(): - with TestMeshAPI.rz_socket(namespace=NS_test) as (_, ns_sock): + with RZ_websocket(namespace=NS_test) as (_, ns_sock): c1_t.switch() # allow peer to connect data = json.dumps(attr_diff) ns_sock.emit('diff_commit__attr', data) c1_t.switch() def c_1(): - with TestMeshAPI.rz_socket(namespace=NS_test) as (sock, _): + with RZ_websocket(namespace=NS_test) as (sock, _): c0_t.switch() # allow peer to emit sock.wait(8) # allow self to receive diff --git a/src/server/rz_mesh.py b/src/server/rz_mesh.py index b173e64d..6336cdb2 100644 --- a/src/server/rz_mesh.py +++ b/src/server/rz_mesh.py @@ -69,13 +69,6 @@ def init_ws_interface(cfg, kernel, flask_webapp): flask_webapp.logger.error("Exception while handling socketio connection", exc_info=True) return Response() - # connect socketio route - route_dec = flask_webapp.route('/socket.io/<path:url_path>') - f = route_dec(socketio_route_handler) - flask_webapp.f = f - - # init ws server - ws_srv = RZ_WebSocket_Server(cfg, flask_webapp) # link ws hooks: multicast on topo_diff, attr_diff def decorator__ws_multicast(ws_srv, f, f_multicast): @@ -111,6 +104,14 @@ def init_ws_interface(cfg, kernel, flask_webapp): return wrapped_function + # connect socketio route + route_dec = flask_webapp.route('/socket.io/<path:url_path>') + f = route_dec(socketio_route_handler) + flask_webapp.f = f + + # init ws server + ws_srv = RZ_WebSocket_Server(cfg, flask_webapp) + kernel.diff_commit__topo = decorator__ws_multicast(ws_srv, kernel.diff_commit__topo, f_multicast=WebSocket_Graph_NS.on_diff_commit__topo) |
