2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
2018-02-20 13:08:50 +01:00
|
|
|
|
2018-03-31 02:38:10 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
dependencies: Remove WebSockets system for sending messages.
Zulip has had a small use of WebSockets (specifically, for the code
path of sending messages, via the webapp only) since ~2013. We
originally added this use of WebSockets in the hope that the latency
benefits of doing so would allow us to avoid implementing a markdown
local echo; they were not. Further, HTTP/2 may have eliminated the
latency difference we hoped to exploit by using WebSockets in any
case.
While we’d originally imagined using WebSockets for other endpoints,
there was never a good justification for moving more components to the
WebSockets system.
This WebSockets code path had a lot of downsides/complexity,
including:
* The messy hack involving constructing an emulated request object to
hook into doing Django requests.
* The `message_senders` queue processor system, which increases RAM
needs and must be provisioned independently from the rest of the
server).
* A duplicate check_send_receive_time Nagios test specific to
WebSockets.
* The requirement for users to have their firewalls/NATs allow
WebSocket connections, and a setting to disable them for networks
where WebSockets don’t work.
* Dependencies on the SockJS family of libraries, which has at times
been poorly maintained, and periodically throws random JavaScript
exceptions in our production environments without a deep enough
traceback to effectively investigate.
* A total of about 1600 lines of our code related to the feature.
* Increased load on the Tornado system, especially around a Zulip
server restart, and especially for large installations like
zulipchat.com, resulting in extra delay before messages can be sent
again.
As detailed in
https://github.com/zulip/zulip/pull/12862#issuecomment-536152397, it
appears that removing WebSockets moderately increases the time it
takes for the `send_message` API query to return from the server, but
does not significantly change the time between when a message is sent
and when it is received by clients. We don’t understand the reason
for that change (suggesting the possibility of a measurement error),
and even if it is a real change, we consider that potential small
latency regression to be acceptable.
If we later want WebSockets, we’ll likely want to just use Django
Channels.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-23 01:43:40 +02:00
|
|
|
set_global('page_params', {});
|
2018-02-20 13:08:50 +01:00
|
|
|
set_global('channel', {});
|
|
|
|
set_global('reload', {});
|
2018-08-04 15:40:25 +02:00
|
|
|
set_global('reload_state', {});
|
2018-02-20 13:08:50 +01:00
|
|
|
set_global('sent_messages', {
|
|
|
|
start_tracking_message: noop,
|
|
|
|
report_server_ack: noop,
|
|
|
|
});
|
|
|
|
|
2018-02-23 16:18:27 +01:00
|
|
|
zrequire('people');
|
2018-02-20 13:08:50 +01:00
|
|
|
zrequire('transmit');
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('transmit_message_ajax', () => {
|
2018-02-20 13:08:50 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let success_func_called;
|
|
|
|
const success = function () {
|
2018-02-20 13:08:50 +01:00
|
|
|
success_func_called = true;
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const request = {foo: 'bar'};
|
2018-02-20 13:08:50 +01:00
|
|
|
|
|
|
|
channel.post = function (opts) {
|
|
|
|
assert.equal(opts.url, '/json/messages');
|
|
|
|
assert.equal(opts.data.foo, 'bar');
|
|
|
|
opts.success();
|
|
|
|
};
|
|
|
|
|
|
|
|
transmit.send_message(request, success);
|
|
|
|
|
|
|
|
assert(success_func_called);
|
|
|
|
|
|
|
|
channel.xhr_error_message = function (msg) {
|
|
|
|
assert.equal(msg, 'Error sending message');
|
|
|
|
return msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.post = function (opts) {
|
|
|
|
assert.equal(opts.url, '/json/messages');
|
|
|
|
assert.equal(opts.data.foo, 'bar');
|
2019-11-02 00:06:25 +01:00
|
|
|
const xhr = 'whatever';
|
2018-02-20 13:08:50 +01:00
|
|
|
opts.error(xhr, 'timeout');
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let error_func_called;
|
|
|
|
const error = function (response) {
|
2018-02-20 13:08:50 +01:00
|
|
|
assert.equal(response, 'Error sending message');
|
|
|
|
error_func_called = true;
|
|
|
|
};
|
|
|
|
transmit.send_message(request, success, error);
|
|
|
|
assert(error_func_called);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-20 13:08:50 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('transmit_message_ajax_reload_pending', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const success = function () { throw 'unexpected success'; };
|
2018-02-20 13:08:50 +01:00
|
|
|
|
2018-08-04 15:40:25 +02:00
|
|
|
reload_state.is_pending = function () {
|
2018-02-20 13:08:50 +01:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let reload_initiated;
|
2018-02-20 13:08:50 +01:00
|
|
|
reload.initiate = function (opts) {
|
|
|
|
reload_initiated = true;
|
|
|
|
assert.deepEqual(opts, {
|
2018-05-07 03:30:13 +02:00
|
|
|
immediate: true,
|
|
|
|
save_pointer: true,
|
|
|
|
save_narrow: true,
|
|
|
|
save_compose: true,
|
|
|
|
send_after_reload: true,
|
2018-02-20 13:08:50 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const request = {foo: 'bar'};
|
2018-02-20 13:08:50 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let error_func_called;
|
|
|
|
const error = function (response) {
|
2018-02-20 13:08:50 +01:00
|
|
|
assert.equal(response, 'Error sending message');
|
|
|
|
error_func_called = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
error_func_called = false;
|
|
|
|
channel.post = function (opts) {
|
|
|
|
assert.equal(opts.url, '/json/messages');
|
|
|
|
assert.equal(opts.data.foo, 'bar');
|
2019-11-02 00:06:25 +01:00
|
|
|
const xhr = 'whatever';
|
2018-02-20 13:08:50 +01:00
|
|
|
opts.error(xhr, 'bad request');
|
|
|
|
};
|
|
|
|
transmit.send_message(request, success, error);
|
|
|
|
assert(!error_func_called);
|
|
|
|
assert(reload_initiated);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-23 16:18:27 +01:00
|
|
|
|
|
|
|
run_test('reply_message_stream', () => {
|
|
|
|
const stream_message = {
|
|
|
|
type: 'stream',
|
|
|
|
stream: 'social',
|
2018-12-23 16:49:14 +01:00
|
|
|
topic: 'lunch',
|
2018-02-23 16:18:27 +01:00
|
|
|
sender_full_name: 'Alice',
|
2018-10-13 02:31:49 +02:00
|
|
|
sender_id: 123,
|
2018-02-23 16:18:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const content = 'hello';
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let send_message_args;
|
2018-02-23 16:18:27 +01:00
|
|
|
|
|
|
|
transmit.send_message = (args) => {
|
|
|
|
send_message_args = args;
|
|
|
|
};
|
|
|
|
|
|
|
|
page_params.user_id = 44;
|
|
|
|
page_params.queue_id = 66;
|
2020-02-12 09:32:25 +01:00
|
|
|
sent_messages.get_new_local_id = () => "99";
|
2018-02-23 16:18:27 +01:00
|
|
|
|
|
|
|
transmit.reply_message({
|
|
|
|
message: stream_message,
|
|
|
|
content: content,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(send_message_args, {
|
|
|
|
sender_id: 44,
|
|
|
|
queue_id: 66,
|
2020-02-12 09:32:25 +01:00
|
|
|
local_id: '99',
|
2018-02-23 16:18:27 +01:00
|
|
|
type: 'stream',
|
|
|
|
to: 'social',
|
|
|
|
content: '@**Alice** hello',
|
2018-12-23 16:49:14 +01:00
|
|
|
topic: 'lunch',
|
2018-02-23 16:18:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test('reply_message_private', () => {
|
|
|
|
const fred = {
|
|
|
|
user_id: 3,
|
|
|
|
email: 'fred@example.com',
|
|
|
|
full_name: 'Fred Frost',
|
|
|
|
};
|
|
|
|
people.add(fred);
|
|
|
|
|
|
|
|
people.is_my_user_id = () => false;
|
|
|
|
|
|
|
|
const pm_message = {
|
|
|
|
type: 'private',
|
|
|
|
display_recipient: [
|
2020-01-01 13:02:34 +01:00
|
|
|
{id: fred.user_id},
|
2018-02-23 16:18:27 +01:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const content = 'hello';
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let send_message_args;
|
2018-02-23 16:18:27 +01:00
|
|
|
|
|
|
|
transmit.send_message = (args) => {
|
|
|
|
send_message_args = args;
|
|
|
|
};
|
|
|
|
|
|
|
|
page_params.user_id = 155;
|
|
|
|
page_params.queue_id = 177;
|
2020-02-12 09:32:25 +01:00
|
|
|
sent_messages.get_new_local_id = () => "199";
|
2018-02-23 16:18:27 +01:00
|
|
|
|
|
|
|
transmit.reply_message({
|
|
|
|
message: pm_message,
|
|
|
|
content: content,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(send_message_args, {
|
|
|
|
sender_id: 155,
|
|
|
|
queue_id: 177,
|
2020-02-12 09:32:25 +01:00
|
|
|
local_id: '199',
|
2018-02-23 16:18:27 +01:00
|
|
|
type: 'private',
|
|
|
|
to: '["fred@example.com"]',
|
|
|
|
content: 'hello',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test('reply_message_errors', () => {
|
|
|
|
const bogus_message = {
|
|
|
|
type: 'bogus',
|
|
|
|
};
|
|
|
|
|
2020-04-03 17:18:04 +02:00
|
|
|
blueslip.expect('error', 'unknown message type: bogus');
|
2018-02-23 16:18:27 +01:00
|
|
|
|
|
|
|
transmit.reply_message({
|
|
|
|
message: bogus_message,
|
|
|
|
});
|
|
|
|
|
2020-04-03 17:18:04 +02:00
|
|
|
blueslip.reset();
|
2018-02-23 16:18:27 +01:00
|
|
|
});
|