Browse Source

delay start of message queue listener thread until first request comes

pull/30/merge
Miguel Grinberg 9 years ago
parent
commit
b6df63d849
  1. 5
      socketio/server.py
  2. 4
      tests/test_server.py

5
socketio/server.py

@ -96,8 +96,8 @@ class Server(object):
if client_manager is None:
client_manager = base_manager.BaseManager()
client_manager.initialize(self)
self.manager = client_manager
self.manager_initialized = False
def on(self, event, handler=None, namespace=None):
"""Register an event handler.
@ -300,6 +300,9 @@ class Server(object):
This function returns the HTTP response body to deliver to the client
as a byte sequence.
"""
if not self.manager_initialized:
self.manager_initialized = True
self.manager.initialize(self)
return self.eio.handle_request(environ, start_response)
def start_background_task(self, target, *args, **kwargs):

4
tests/test_server.py

@ -21,10 +21,13 @@ class TestServer(unittest.TestCase):
def test_create(self, eio):
mgr = mock.MagicMock()
s = server.Server(client_manager=mgr, binary=True, foo='bar')
s.handle_request({}, None)
s.handle_request({}, None)
eio.assert_called_once_with(**{'foo': 'bar'})
self.assertEqual(s.manager, mgr)
self.assertEqual(s.eio.on.call_count, 3)
self.assertEqual(s.binary, True)
self.assertEqual(mgr.initialize.call_count, 1)
def test_on_event(self, eio):
s = server.Server()
@ -285,6 +288,7 @@ class TestServer(unittest.TestCase):
def test_handle_event_binary_ack(self, eio):
s = server.Server()
s.manager.initialize(s)
s._handle_eio_message('123', '61-1["my message","a",'
'{"_placeholder":true,"num":0}]')
self.assertEqual(s._attachment_count, 1)

Loading…
Cancel
Save