Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that moving presence off master works #1025

Merged
merged 6 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 61 additions & 16 deletions lib/SyTest/Homeserver/Synapse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ sub _init
event_persister2 => main::alloc_port( "event_persister2[$idx]" ),
event_persister2_metrics => main::alloc_port( "event_persister2[$idx].metrics" ),
event_persister2_manhole => main::alloc_port( "event_persister2[$idx].manhole" ),

stream_writer => main::alloc_port( "stream_writer[$idx]" ),
stream_writer_metrics => main::alloc_port( "stream_writer[$idx].metrics" ),
stream_writer_manhole => main::alloc_port( "stream_writer[$idx].manhole" ),
};
}

Expand Down Expand Up @@ -309,17 +313,19 @@ sub start
host => "$bind_host",
port => $self->{ports}{client_reader},
},
"stream_writer" => {
host => "$bind_host",
port => $self->{ports}{stream_writer},
},
},

stream_writers => {
events => $self->{redis_host} ne '' ? [ "event_persister1", "event_persister2" ] : "master",

# There's no particular reason to choose client_reader, but I
# couldn't think of a better place and I'm not sure we want to add
# more workers at this point
to_device => $self->{redis_host} ne '' ? [ "client_reader" ] : "master",
account_data => $self->{redis_host} ne '' ? [ "client_reader" ] : "master",
receipts => $self->{redis_host} ne '' ? [ "client_reader" ] : "master",
to_device => $self->{redis_host} ne '' ? [ "stream_writer" ] : "master",
account_data => $self->{redis_host} ne '' ? [ "stream_writer" ] : "master",
receipts => $self->{redis_host} ne '' ? [ "stream_writer" ] : "master",
presence => $self->{redis_host} ne '' ? [ "stream_writer" ] : "master",
},

# We use a high limit so the limit is never reached, but enabling the
Expand Down Expand Up @@ -1050,6 +1056,40 @@ sub _start_synapse
push @worker_configs, $event_persister2_config;
}

{
my $stream_writer_config = {
"worker_app" => "synapse.app.generic_worker",
"worker_name" => "stream_writer",
"worker_pid_file" => "$hsdir/stream_writer.pid",
"worker_log_config" => $self->configure_logger("stream_writer"),
"worker_replication_host" => "$bind_host",
"worker_replication_port" => $self->{ports}{synapse_replication_tcp},
"worker_replication_http_port" => $self->{ports}{synapse_unsecure},
"worker_main_http_uri" => "http://$bind_host:$self->{ports}{synapse_unsecure}",
"worker_listeners" => [
{
type => "http",
resources => [{ names => ["client", "replication"] }],
port => $self->{ports}{stream_writer},
bind_address => $bind_host,
},
{
type => "manhole",
port => $self->{ports}{stream_writer_manhole},
bind_address => $bind_host,
},
{
type => "http",
resources => [{ names => ["metrics"] }],
port => $self->{ports}{stream_writer_metrics},
bind_address => $bind_host,
},
],
};

push @worker_configs, $stream_writer_config;
}

my @base_synapse_command = $self->_generate_base_synapse_command();
my $idx = $self->{hs_index};

Expand Down Expand Up @@ -1201,6 +1241,9 @@ backend event_creator
backend frontend_proxy
server frontend_proxy ${bind_host}:$ports->{frontend_proxy}

backend stream_writer
server stream_writer ${bind_host}:$ports->{stream_writer}

EOCONFIG
}

Expand Down Expand Up @@ -1246,9 +1289,6 @@ sub generate_haproxy_map
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state$ client_reader
^/_matrix/client/(api/v1|r0|unstable)/login$ client_reader
^/_matrix/client/(api/v1|r0|unstable)/account/3pid$ client_reader
^/_matrix/client/(api/v1|r0|unstable)/devices$ client_reader
^/_matrix/client/(api/v1|r0|unstable)/keys/query$ client_reader
^/_matrix/client/(api/v1|r0|unstable)/keys/changes$ client_reader
^/_matrix/client/versions$ client_reader
^/_matrix/client/(api/v1|r0|unstable)/voip/turnServer$ client_reader
^/_matrix/client/(r0|unstable)/register$ client_reader
Expand All @@ -1258,8 +1298,13 @@ sub generate_haproxy_map
^/_matrix/client/(api/v1|r0|unstable)/joined_groups$ client_reader
^/_matrix/client/(api/v1|r0|unstable)/publicised_groups$ client_reader
^/_matrix/client/(api/v1|r0|unstable)/publicised_groups/ client_reader
^/_matrix/client/(api/v1|r0|unstable)/keys/claim client_reader
^/_matrix/client/(api/v1|r0|unstable)/room_keys client_reader

^/_matrix/client/(api/v1|r0|unstable)/devices$ stream_writer
^/_matrix/client/(api/v1|r0|unstable)/keys/query$ stream_writer
^/_matrix/client/(api/v1|r0|unstable)/keys/changes$ stream_writer
^/_matrix/client/(api/v1|r0|unstable)/keys/claim stream_writer
^/_matrix/client/(api/v1|r0|unstable)/room_keys stream_writer
^/_matrix/client/(api/v1|r0|unstable)/presence/ stream_writer

^/_matrix/client/(api/v1|r0|unstable)/keys/upload frontend_proxy

Expand All @@ -1277,11 +1322,11 @@ EOCONFIG
if ( $self->{redis_host} ne '' ) {
$haproxy_map .= <<'EOCONFIG';

^/_matrix/client/(api/v1|r0|unstable)/sendToDevice/ client_reader
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/tag client_reader
^/_matrix/client/(api/v1|r0|unstable)/.*/account_data client_reader
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/receipt client_reader
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/read_markers client_reader
^/_matrix/client/(api/v1|r0|unstable)/sendToDevice/ stream_writer
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/tag stream_writer
^/_matrix/client/(api/v1|r0|unstable)/.*/account_data stream_writer
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/receipt stream_writer
^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/read_markers stream_writer

EOCONFIG
}
Expand Down
30 changes: 15 additions & 15 deletions tests/10apidoc/20presence.pl
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ sub matrix_set_presence_status

proves => [qw( can_set_presence )],

do => sub {
check => sub {
my ( $user ) = @_;

matrix_set_presence_status( $user, "online",
status_msg => $status_msg,
)
},

check => sub {
my ( $user ) = @_;

matrix_get_presence_status( $user )->then( sub {
my ( $body ) = @_;

( $body->{status_msg} // "" ) eq $status_msg or
die "Incorrect status_msg";

Future->done(1);
});
)->then( sub {
# If presence is on a different worker it may take a while for it to
# propagate.
Comment on lines +80 to +81
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users always receive their own presence down sync:

test "User sees their own presence in a sync",

In which case, it might be better to write a matrix_set_presence_status_synced method.

...but also: meh, this works.

retry_until_success {
matrix_get_presence_status( $user )->then( sub {
my ( $body ) = @_;

( $body->{status_msg} // "" ) eq $status_msg or
die "Incorrect status_msg";

Future->done(1);
});
}
})
};