From 802149fa529f8cdd36037990e626c515789fe025 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 2 Jun 2020 15:13:28 +0100 Subject: [PATCH] Have frontend proxy persist events when using redis (#870) --- lib/SyTest/Homeserver/Synapse.pm | 14 +++++- tests/10apidoc/33room-members.pl | 4 +- tests/10apidoc/36room-levels.pl | 2 +- tests/30rooms/05aliases.pl | 36 +++++++++------ tests/30rooms/06invite.pl | 2 +- tests/30rooms/07ban.pl | 40 +++++++++------- tests/30rooms/12thirdpartyinvite.pl | 54 +++++++++++++--------- tests/30rooms/60version_upgrade.pl | 28 ++++++----- tests/31sync/06state.pl | 4 +- tests/31sync/15lazy-members.pl | 2 +- tests/41end-to-end-keys/06-device-lists.pl | 50 ++++++++++---------- tests/48admin.pl | 15 +++--- tests/50federation/31room-send.pl | 4 +- tests/52user-directory/01public.pl | 4 +- tests/90jira/SYN-442.pl | 5 +- 15 files changed, 155 insertions(+), 109 deletions(-) diff --git a/lib/SyTest/Homeserver/Synapse.pm b/lib/SyTest/Homeserver/Synapse.pm index 309a98516..532305812 100644 --- a/lib/SyTest/Homeserver/Synapse.pm +++ b/lib/SyTest/Homeserver/Synapse.pm @@ -277,6 +277,17 @@ sub start }, ) : (), + instance_map => { + "frontend_proxy1" => { + host => "$bind_host", + port => $self->{ports}{frontend_proxy}, + }, + }, + + stream_writers => { + events => $self->{redis_host} ne '' ? "frontend_proxy1" : "master", + }, + # We use a high limit so the limit is never reached, but enabling the # limit ensures that the code paths get hit. This helps testing the # feature with worker mode. @@ -988,6 +999,7 @@ sub wrap_synapse_command { my $frontend_proxy_config_path = $self->write_yaml_file( "frontend_proxy.yaml" => { "worker_app" => "synapse.app.frontend_proxy", + "worker_name" => "frontend_proxy1", "worker_pid_file" => "$hsdir/frontend_proxy.pid", "worker_log_config" => $self->configure_logger("frontend_proxy"), "worker_replication_host" => "$bind_host", @@ -997,7 +1009,7 @@ sub wrap_synapse_command "worker_listeners" => [ { type => "http", - resources => [{ names => ["client"] }], + resources => [{ names => ["client", "replication"] }], port => $self->{ports}{frontend_proxy}, bind_address => $bind_host, }, diff --git a/tests/10apidoc/33room-members.pl b/tests/10apidoc/33room-members.pl index 12339f002..1fc8b22ed 100644 --- a/tests/10apidoc/33room-members.pl +++ b/tests/10apidoc/33room-members.pl @@ -496,6 +496,8 @@ sub matrix_create_and_join_room } @local_members, ) })->then( sub { + log_if_fail "Created room_id=$room_id"; + Future->done( $room_id, ( $with_alias ? ( $room_alias_fullname ) : () ) ); @@ -660,7 +662,7 @@ sub matrix_join_room_synced matrix_do_and_wait_for_sync( $user, do => sub { - matrix_join_room( $user, $room_id_or_alias, %params ); + retry_until_success { matrix_join_room( $user, $room_id_or_alias, %params ) } }, check => sub { exists $_[0]->{rooms}{join}{$_[1]} }, ); diff --git a/tests/10apidoc/36room-levels.pl b/tests/10apidoc/36room-levels.pl index 8ffed904c..3c98a4f08 100644 --- a/tests/10apidoc/36room-levels.pl +++ b/tests/10apidoc/36room-levels.pl @@ -139,7 +139,7 @@ sub matrix_change_room_power_levels my ( $levels ) = @_; $func->( $levels ); - matrix_put_room_state( $user, $room_id, type => "m.room.power_levels", + matrix_put_room_state_synced( $user, $room_id, type => "m.room.power_levels", content => $levels, ); }); diff --git a/tests/30rooms/05aliases.pl b/tests/30rooms/05aliases.pl index 2f3cb5bf2..e3efcab3b 100644 --- a/tests/30rooms/05aliases.pl +++ b/tests/30rooms/05aliases.pl @@ -219,15 +219,19 @@ $_[0]->{events}->{'m.room.aliases'} = 50; }, )->then( sub { - matrix_get_room_state( $creator, $room_id, - type => "m.room.power_levels", - ); - })->then( sub { - my ( $body ) = @_; - log_if_fail "power levels", $body; + retry_until_success { + matrix_get_room_state( $creator, $room_id, + type => "m.room.power_levels", + )->then( sub { + my ( $body ) = @_; + log_if_fail "power levels", $body; - assert_eq( $body->{events}->{'m.room.aliases'}, 50 ); + assert_eq( $body->{events}->{'m.room.aliases'}, 50 ); + Future->done( 1 ) + }) + } + })->then( sub { do_request_json_for( $other_user, method => "PUT", uri => "/r0/directory/room/$alias", @@ -364,7 +368,7 @@ sub _test_can_create_and_delete_alias { content => { room_id => $room_id }, ) })->then( sub { - matrix_put_room_state( $creator, $room_id, + matrix_put_room_state_synced( $creator, $room_id, type => "m.room.canonical_alias", content => { alias => $room_alias } ) @@ -376,15 +380,17 @@ sub _test_can_create_and_delete_alias { content => {}, ) })->then( sub { - matrix_get_room_state( $creator, $room_id, - type => "m.room.canonical_alias", - ) - })->then( sub { - my ( $body ) = @_; + retry_until_success { + matrix_get_room_state( $creator, $room_id, + type => "m.room.canonical_alias", + )->then( sub { + my ( $body ) = @_; - not defined $body->{alias} or die "Expected canonical alias to be empty"; + not defined $body->{alias} or die "Expected canonical alias to be empty"; - Future->done( 1 ); + Future->done( 1 ); + }) + } }) }; diff --git a/tests/30rooms/06invite.pl b/tests/30rooms/06invite.pl index d5645fe00..798325abe 100644 --- a/tests/30rooms/06invite.pl +++ b/tests/30rooms/06invite.pl @@ -137,7 +137,7 @@ sub invited_user_can_reject_invite matrix_invite_user_to_room( $creator, $invitee, $room_id ) ->then( sub { - matrix_leave_room( $invitee, $room_id ) + matrix_leave_room_synced( $invitee, $room_id ) })->then( sub { matrix_get_room_state( $creator, $room_id, type => "m.room.member", diff --git a/tests/30rooms/07ban.pl b/tests/30rooms/07ban.pl index 515af2910..0bf7b9cb2 100644 --- a/tests/30rooms/07ban.pl +++ b/tests/30rooms/07ban.pl @@ -16,15 +16,19 @@ content => { user_id => $banned_user->user_id, reason => "testing" }, )->then( sub { - matrix_get_room_state( $creator, $room_id, - type => "m.room.member", - state_key => $banned_user->user_id, - ) + retry_until_success { + matrix_get_room_state( $creator, $room_id, + type => "m.room.member", + state_key => $banned_user->user_id, + )->then( sub { + my ( $body ) = @_; + $body->{membership} eq "ban" or + die "Expected banned user membership to be 'ban'"; + + Future->done( 1 ) + }) + } })->then( sub { - my ( $body ) = @_; - $body->{membership} eq "ban" or - die "Expected banned user membership to be 'ban'"; - matrix_join_room( $banned_user, $room_id ) ->main::expect_http_403; # Must be unbanned first })->then( sub { @@ -75,15 +79,19 @@ content => { user_id => $banned_user->user_id, reason => "testing" }, )->then( sub { - matrix_get_room_state( $creator, $room_id, - type => "m.room.member", - state_key => $banned_user->user_id, - ) + retry_until_success { + matrix_get_room_state( $creator, $room_id, + type => "m.room.member", + state_key => $banned_user->user_id, + )->then( sub { + my ( $body ) = @_; + $body->{membership} eq "ban" or + die "Expected banned user membership to be 'ban'"; + + Future->done( 1 ) + }) + } })->then( sub { - my ( $body ) = @_; - $body->{membership} eq "ban" or - die "Expected banned user membership to be 'ban'"; - repeat_until_true { matrix_get_room_state( $banned_user, $room_id, type => "m.room.member", diff --git a/tests/30rooms/12thirdpartyinvite.pl b/tests/30rooms/12thirdpartyinvite.pl index 2b68b672c..19a5db28a 100644 --- a/tests/30rooms/12thirdpartyinvite.pl +++ b/tests/30rooms/12thirdpartyinvite.pl @@ -78,16 +78,18 @@ }, ); })->then( sub { - matrix_get_room_state( $inviter, $room_id, - type => "m.room.member", - state_key => $invitee_mxid, - ); - })->on_done( sub { - my ( $body ) = @_; - - log_if_fail "Body", $body; - assert_eq( $body->{membership}, "invite", - 'invited user membership' ); + retry_until_success { + matrix_get_room_state( $inviter, $room_id, + type => "m.room.member", + state_key => $invitee_mxid, + )->on_done( sub { + my ( $body ) = @_; + + log_if_fail "Body", $body; + assert_eq( $body->{membership}, "invite", + 'invited user membership' ); + }) + } }); }; @@ -236,13 +238,17 @@ sub can_invite_unbound_3pid log_if_fail "m.room.member invite", $body; assert_eq( $body->{third_party_invite}{display_name}, 'Bob', 'invite display name' ); - matrix_join_room( $invitee, $room_id ) + retry_until_success { + matrix_join_room( $invitee, $room_id ) + } })->then( sub { - matrix_get_room_state( $inviter, $room_id, - type => "m.room.member", - state_key => $invitee->user_id, - ) - })->followed_by( assert_membership( "join" ) ); + retry_until_success { + matrix_get_room_state( $inviter, $room_id, + type => "m.room.member", + state_key => $invitee->user_id, + )->followed_by( assert_membership( "join" ) ) + } + }) } test "Can invite unbound 3pid over federation with users from both servers", @@ -289,7 +295,9 @@ sub can_invite_unbound_3pid log_if_fail "m.room.member invite", $body; assert_eq( $body->{third_party_invite}{display_name}, 'Bob', 'invite display name' ); - matrix_join_room( $invitee, $room_id ) + retry_until_success { + matrix_join_room( $invitee, $room_id ) + } })->then( sub { await_event_for( $inviter, filter => sub { my ( $event ) = @_; @@ -301,11 +309,13 @@ sub can_invite_unbound_3pid return 1; }) })->then( sub { - matrix_get_room_state( $inviter, $room_id, - type => "m.room.member", - state_key => $invitee->user_id, - ) - })->followed_by( assert_membership( "join" ) ); + retry_until_success { + matrix_get_room_state( $inviter, $room_id, + type => "m.room.member", + state_key => $invitee->user_id, + )->followed_by( assert_membership( "join" ) ) + } + }); }; test "Can accept unbound 3pid invite after inviter leaves", diff --git a/tests/30rooms/60version_upgrade.pl b/tests/30rooms/60version_upgrade.pl index 6fa88605a..8f4c58ee7 100644 --- a/tests/30rooms/60version_upgrade.pl +++ b/tests/30rooms/60version_upgrade.pl @@ -674,7 +674,7 @@ sub upgrade_room_synced { ); })->then( sub { # alias 1 is the canonical alias. - matrix_put_room_state( $creator, $room_id, + matrix_put_room_state_synced( $creator, $room_id, type => "m.room.canonical_alias", content => { alias => $room_alias_1, @@ -757,7 +757,7 @@ sub upgrade_room_synced { $creator, $remote_user, $room_id )->then( sub { # Have the remote user join the room - matrix_join_room( $remote_user, $room_id ); + matrix_join_room_synced( $remote_user, $room_id ); })->then( sub { # Have the remote user add an alias do_request_json_for( @@ -781,20 +781,24 @@ sub upgrade_room_synced { ); })->then( sub { # Have the remote user join the upgraded room - matrix_join_room( $remote_user, $new_room_id ); + matrix_join_room_synced( $remote_user, $new_room_id ); })->then( sub { # Check that the remote alias points to the new room id - do_request_json_for( - $remote_user, - method => "GET", - uri => "/r0/directory/room/$remote_room_alias", - ); - })->then( sub { - my ( $body ) = @_; + retry_until_success { + do_request_json_for( + $remote_user, + method => "GET", + uri => "/r0/directory/room/$remote_room_alias", + )->then( sub { + my ( $body ) = @_; - assert_eq( $body->{room_id}, $new_room_id, "room_id for remote alias" ); + log_if_fail "Got room ID for alias", $body->{room_id}; - Future->done(1); + assert_eq( $body->{room_id}, $new_room_id, "room_id for remote alias" ); + + Future->done(1); + }) + } }); }; diff --git a/tests/31sync/06state.pl b/tests/31sync/06state.pl index 5d508ec27..821ffbfaa 100644 --- a/tests/31sync/06state.pl +++ b/tests/31sync/06state.pl @@ -774,7 +774,7 @@ qw( can_sync ) ], # sending 50 messages can take a while - timeout => 20000, + timeout => 20, check => sub { my ( $creator, $syncer, $invitee ) = @_; @@ -834,7 +834,7 @@ qw( can_sync ) ], # sending 50 messages can take a while - timeout => 20000, + timeout => 20, check => sub { my ( $creator, $syncer, $invitee ) = @_; diff --git a/tests/31sync/15lazy-members.pl b/tests/31sync/15lazy-members.pl index 3c9925e55..bbcf7c50a 100644 --- a/tests/31sync/15lazy-members.pl +++ b/tests/31sync/15lazy-members.pl @@ -286,7 +286,7 @@ test "Gapped incremental syncs include all state changes", # sending 50 messages can take a while - timeout => 20000, + timeout => 20, requires => [ local_user_fixtures( 4 ), qw( can_sync ) ], diff --git a/tests/41end-to-end-keys/06-device-lists.pl b/tests/41end-to-end-keys/06-device-lists.pl index b47ee5902..b7995f7d6 100644 --- a/tests/41end-to-end-keys/06-device-lists.pl +++ b/tests/41end-to-end-keys/06-device-lists.pl @@ -180,12 +180,12 @@ sub sync_until_user_in_device_list my $room_id; - matrix_create_room( $user1 )->then( sub { + matrix_create_room_synced( $user1 )->then( sub { ( $room_id ) = @_; - matrix_invite_user_to_room( $user1, $user2, $room_id ) + matrix_invite_user_to_room_synced( $user1, $user2, $room_id ) })->then( sub { - matrix_join_room( $user2, $room_id ); + matrix_join_room_synced( $user2, $room_id ); })->then( sub { matrix_sync( $user1 ); })->then( sub { @@ -236,12 +236,12 @@ sub sync_until_user_in_device_list my $room_id; - matrix_create_room( $user1 )->then( sub { + matrix_create_room_synced( $user1 )->then( sub { ( $room_id ) = @_; - matrix_invite_user_to_room( $user1, $user2, $room_id ) + matrix_invite_user_to_room_synced( $user1, $user2, $room_id ) })->then( sub { - matrix_join_room( $user2, $room_id ); + matrix_join_room_synced( $user2, $room_id ); })->then( sub { matrix_sync( $user1 ); })->then( sub { @@ -295,12 +295,12 @@ sub sync_until_user_in_device_list my $room_id; - matrix_create_room( $creator, + matrix_create_room_synced( $creator, invite => [ $remote_leaver->user_id ], )->then( sub { ( $room_id ) = @_; - matrix_join_room( $remote_leaver, $room_id ); + matrix_join_room_synced( $remote_leaver, $room_id ); })->then( sub { matrix_sync( $creator ); })->then( sub { @@ -344,18 +344,18 @@ sub sync_until_user_in_device_list my $room_id; - matrix_create_room( $creator )->then( sub { + matrix_create_room_synced( $creator )->then( sub { ( $room_id ) = @_; matrix_sync( $creator ); })->then( sub { - matrix_invite_user_to_room( $creator, $remote_leaver, $room_id ) + matrix_invite_user_to_room_synced( $creator, $remote_leaver, $room_id ) })->then( sub { - matrix_join_room( $remote_leaver, $room_id ); + matrix_join_room_synced( $remote_leaver, $room_id ); })->then( sub { - matrix_invite_user_to_room( $creator, $remote2, $room_id ) + matrix_invite_user_to_room_synced( $creator, $remote2, $room_id ) })->then( sub { - matrix_join_room( $remote2, $room_id ); + matrix_join_room_synced( $remote2, $room_id ); })->then( sub { log_if_fail "Created and joined room"; @@ -442,10 +442,10 @@ sub sync_until_user_in_device_list my ( $room_id, $from_token, $to_token ); - matrix_create_room( $user1 )->then( sub { + matrix_create_room_synced( $user1 )->then( sub { ( $room_id ) = @_; - matrix_join_room( $user2, $room_id ); + matrix_join_room_synced( $user2, $room_id ); })->then( sub { matrix_sync( $user1 ); })->then( sub { @@ -504,7 +504,7 @@ sub sync_until_user_in_device_list my ( $room_id, $from_token, $to_token ); - matrix_create_room( $user1 )->then( sub { + matrix_create_room_synced( $user1 )->then( sub { ( $room_id ) = @_; matrix_sync( $user1 ); @@ -556,12 +556,12 @@ sub sync_until_user_in_device_list my ( $room_id, $from_token, $to_token ); - matrix_create_room( $creator, + matrix_create_room_synced( $creator, invite => [ $remote_leaver->user_id ], )->then( sub { ( $room_id ) = @_; - matrix_join_room( $remote_leaver, $room_id ); + matrix_join_room_synced( $remote_leaver, $room_id ); })->then( sub { matrix_sync( $creator ); })->then( sub { @@ -618,12 +618,12 @@ sub sync_until_user_in_device_list my ( $room_id, $from_token ); - matrix_create_room( $creator, + matrix_create_room_synced( $creator, invite => [ $other_user->user_id ], )->then( sub { ( $room_id ) = @_; - matrix_join_room( $other_user, $room_id ); + matrix_join_room_synced( $other_user, $room_id ); })->then( sub { matrix_sync( $creator ); })->then( sub { @@ -674,12 +674,12 @@ sub sync_until_user_in_device_list my ( $room_id, $from_token ); - matrix_create_room( $creator, + matrix_create_room_synced( $creator, invite => [ $other_user->user_id ], )->then( sub { ( $room_id ) = @_; - matrix_join_room( $other_user, $room_id ); + matrix_join_room_synced( $other_user, $room_id ); })->then( sub { matrix_sync( $creator ); })->then( sub { @@ -729,13 +729,13 @@ sub sync_until_user_in_device_list my ( $room_id, $from_token, $to_token ); - matrix_create_room( $creator, + matrix_create_room_synced( $creator, invite => [ $remote_user->user_id ], preset => "private_chat", # Allow default PL users to invite others )->then( sub { ( $room_id ) = @_; - matrix_join_room( $remote_user, $room_id ); + matrix_join_room_synced( $remote_user, $room_id ); })->then( sub { matrix_sync( $creator ); })->then( sub { @@ -757,7 +757,7 @@ sub sync_until_user_in_device_list matrix_invite_user_to_room( $remote_user, $creator, $room_id ) } })->then( sub { - matrix_join_room( $creator, $room_id ); + matrix_join_room_synced( $creator, $room_id ) })->then( sub { sync_until_user_in_device_list( $creator, $remote_user, msg => 'Second body', diff --git a/tests/48admin.pl b/tests/48admin.pl index 838db834e..268dcd7cc 100644 --- a/tests/48admin.pl +++ b/tests/48admin.pl @@ -387,6 +387,8 @@ sub await_purge_complete { $new_room_id = $body->{new_room_id}; + log_if_fail "Shutdown room, new room ID", $new_room_id; + matrix_send_room_text_message( $user, $room_id, body => "Hello" ) ->main::expect_http_403; })->SyTest::pass_on_done( "User cannot post in room" ) @@ -412,12 +414,13 @@ sub await_purge_complete { pass( "Aliases were repointed" ); - matrix_get_room_state( $user, $new_room_id, - type => "m.room.name", - state_key => "", - ); - })->SyTest::pass_on_done( "User was added to new room" ) - ->then( sub { + retry_until_success { + matrix_get_room_state( $user, $new_room_id, + type => "m.room.name", + state_key => "", + )->SyTest::pass_on_done( "User was added to new room" ) + } + })->then( sub { matrix_send_room_text_message( $user, $new_room_id, body => "Hello" ) ->main::expect_http_403; })->SyTest::pass_on_done( "User cannot send into new room" ); diff --git a/tests/50federation/31room-send.pl b/tests/50federation/31room-send.pl index 945b16d1e..fe2d528f1 100644 --- a/tests/50federation/31room-send.pl +++ b/tests/50federation/31room-send.pl @@ -154,8 +154,8 @@ my $filter = '{"types":["m.room.message"]}'; - matrix_invite_user_to_room( $local_user, $federated_user, $room_id )->then( sub { - matrix_join_room( $federated_user, $room_id ) + matrix_invite_user_to_room_synced( $local_user, $federated_user, $room_id )->then( sub { + matrix_join_room_synced( $federated_user, $room_id ) })->then( sub { my $now_ms = int( time() * 1000 ); diff --git a/tests/52user-directory/01public.pl b/tests/52user-directory/01public.pl index 641b962b9..a7420c0af 100644 --- a/tests/52user-directory/01public.pl +++ b/tests/52user-directory/01public.pl @@ -152,7 +152,7 @@ requires => [ local_user_fixtures( 2 ) ], # matrix_get_user_dir_synced creates two new users and a room, which is kinda slow. - timeout => 20000, + timeout => 20, check => sub { my ( $creator, $user ) = @_; @@ -250,7 +250,7 @@ requires => [ local_user_fixtures( 2 ) ], # matrix_get_user_dir_synced creates two new users and a room, which is kinda slow. - timeout => 20000, + timeout => 20, check => sub { my ( $creator, $user ) = @_; diff --git a/tests/90jira/SYN-442.pl b/tests/90jira/SYN-442.pl index 779a958fe..9573b8b79 100644 --- a/tests/90jira/SYN-442.pl +++ b/tests/90jira/SYN-442.pl @@ -68,7 +68,8 @@ })->SyTest::pass_on_done( "User A received the invite from user B" ) })->then( sub { - matrix_join_room( $user_1, $room_id ) - ->SyTest::pass_on_done( "User A joined the room" ) + retry_until_success { + matrix_join_room( $user_1, $room_id ) + }->SyTest::pass_on_done( "User A joined the room" ) })->then_done(1); };