diff --git a/zephyr/lib/actions.py b/zephyr/lib/actions.py index 4600b90ef9..139ebbe65e 100644 --- a/zephyr/lib/actions.py +++ b/zephyr/lib/actions.py @@ -297,7 +297,7 @@ def do_send_messages(messages): cache_save_message(message['message']) # We can only publish messages to longpolling clients if the Tornado server is running. - if settings.TORNADO_SERVER: + if True: for message in messages: # Render Markdown etc. here and store (automatically) in # memcached, so that the single-threaded Tornado server diff --git a/zephyr/tests.py b/zephyr/tests.py index 799211e577..64627f00bb 100644 --- a/zephyr/tests.py +++ b/zephyr/tests.py @@ -1555,10 +1555,22 @@ class S3Test(AuthedTestCase): self.test_uris.remove(uri) +class DummyStream: + def closed(self): + return False + +class DummyObject: + pass + +class DummyTornadoRequest: + def __init__(self): + self.connection = DummyObject() + self.connection.stream = DummyStream() class DummyHandler(object): def __init__(self, assert_callback): self.assert_callback = assert_callback + self.request = DummyTornadoRequest() # Mocks RequestHandler.async_callback, which wraps a callback to # handle exceptions. We return the callback as-is. @@ -1568,10 +1580,11 @@ class DummyHandler(object): def write(self, response): raise NotImplemented - def finish(self, response): + def humbug_finish(self, response, *ignore): if self.assert_callback: self.assert_callback(response) + class DummySession(object): session_key = "0" @@ -1589,18 +1602,25 @@ class GetUpdatesTest(AuthedTestCase): def common_test_get_updates(self, view_func, extra_post_data = {}): user_profile = self.get_user_profile("hamlet@humbughq.com") + message_content = 'tornado test message' + self.got_callback = False def callback(response): - correct_message_ids = [m.id for m in - filter_by_subscriptions(Message.objects.all(), user_profile)] - for message in response['messages']: - self.assertGreater(message['id'], 1) - self.assertIn(message['id'], correct_message_ids) + self.got_callback = True + msg = response['messages'][0] + if str(msg['content_type']) == 'text/html': + self.assertEqual('

%s

' % message_content, msg['content']) + else: + self.assertEqual(message_content, msg['content']) post_data = {} post_data.update(extra_post_data) request = POSTRequestMock(post_data, user_profile, callback) self.assertEqual(view_func(request), RespondAsynchronously) + self.send_message("hamlet@humbughq.com", "hamlet@humbughq.com", + Recipient.PERSONAL, message_content) + self.assertTrue(self.got_callback) + def test_json_get_updates(self): """ diff --git a/zephyr/tornado_callbacks.py b/zephyr/tornado_callbacks.py index 63400bd040..3962e43297 100644 --- a/zephyr/tornado_callbacks.py +++ b/zephyr/tornado_callbacks.py @@ -120,7 +120,7 @@ def initialize_user_messages(): stream = streams[m.recipient.type_id] add_stream_message(stream.realm.id, stream.name, m.id) - if not settings.DEPLOYED: + if not settings.DEPLOYED and not settings.TEST_SUITE: # Filling the memcached cache is a little slow, so do it in a child process. # For DEPLOYED cases, we run this from restart_server. subprocess.Popen(["python", os.path.join(os.path.dirname(__file__), "..", "manage.py"), @@ -352,6 +352,8 @@ def send_notification_http(data): requests.post(settings.TORNADO_SERVER + '/notify_tornado', data=dict( data = ujson.dumps(data), secret = settings.SHARED_SECRET)) + else: + process_notification(data) def send_notification(data): return queue_json_publish("notify_tornado", data, send_notification_http)