From 106c0b71bcd650b57aedf794da7c9c0cb58a52cc Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 11 Sep 2020 23:42:43 +0100 Subject: [PATCH 1/9] suggest some more local fed tests --- tests/31sync/17peeking.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/31sync/17peeking.pl b/tests/31sync/17peeking.pl index 2e23ead0e..470453c48 100644 --- a/tests/31sync/17peeking.pl +++ b/tests/31sync/17peeking.pl @@ -213,6 +213,8 @@ # test "Users can peek, unpeek and peek again" +# test "Peeking into an unknown room returns the right error" + # test "Peeking with full_state=true does the right thing" # test "Joining a peeked room moves it atomically from peeked to joined rooms and stops peeking" @@ -220,3 +222,5 @@ # test "Parting a room which was joined after being peeked doesn't go back to being peeked" # test "Changing history visibility to non-world_readable terminates peeks" + +# test "Users can peek local EDUs" From bbcd840ede5d4d177205c850f771c1d329a284b6 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 11 Sep 2020 23:43:02 +0100 Subject: [PATCH 2/9] first cut at testing peeking over fed --- tests/50federation/44peeking.pl | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/50federation/44peeking.pl diff --git a/tests/50federation/44peeking.pl b/tests/50federation/44peeking.pl new file mode 100644 index 000000000..0487129bc --- /dev/null +++ b/tests/50federation/44peeking.pl @@ -0,0 +1,87 @@ +# see 31sync/17peeking.pl for local peeking tests + +my $room_alias_name = sprintf("peektest-%s", $TEST_RUN_ID); +test "Users can peek into world-readable remote rooms", + requires => [ + local_user_and_room_fixtures(room_opts => { room_alias_name => $room_alias_name }), + remote_user_fixture() + ], + + check => sub { + my ( $user, $room_id, $peeking_user ) = @_; + + matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub { + do_request_json_for( $peeking_user, + method => "POST", + uri => "/r0/peek/#$room_alias_name:".$user->http->server_name, + content => {}, + ) + })->then( sub { + matrix_send_room_text_message_synced( $user, $room_id, body => "something to peek"); + })->then(sub { + await_sync( $peeking_user, + since => $peeking_user->sync_next_batch, + check => sub { + my ( $body ) = @_; + return 0 unless $body->{rooms}{peek}{$room_id}; + return $body; + } + ) + })->then( sub { + my ( $body ) = @_; + $peeking_user->sync_next_batch = $body->{next_batch}; + + log_if_fail "sync response", $body; + + my $room = $body->{rooms}{peek}{$room_id}; + assert_json_keys( $room, qw( timeline state ephemeral )); + assert_json_keys( $room->{timeline}, qw( events limited prev_batch )); + assert_json_keys( $room->{state}, qw( events )); + assert_json_keys( $room->{ephemeral}, qw( events )); + + assert_ok( $room->{timeline}->{events}->[0]->{type} eq 'm.room.create', "peek has m.room.create" ); + assert_ok( $room->{timeline}->{events}->[-1]->{type} eq 'm.room.message', "peek has message type" ); + assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something to peek', "peek has message body" ); + assert_ok( @{$room->{state}->{events}} == 0 ); + + assert_ok( scalar keys(%{$body->{rooms}{join}}) == 0, "no joined rooms present"); + })->then( sub { + matrix_send_room_text_message_synced( $user, $room_id, body => "something else to peek"); + })->then( sub { + await_sync( $peeking_user, + since => $peeking_user->sync_next_batch, + check => sub { + my ( $body ) = @_; + return 0 unless $body->{rooms}{peek}{$room_id}; + return $body; + } + ) + })->then( sub { + my ( $body ) = @_; + $peeking_user->sync_next_batch = $body->{next_batch}; + + log_if_fail "next sync response", $body; + my $room = $body->{rooms}{peek}{$room_id}; + + assert_ok( $room->{timeline}->{events}->[-1]->{type} eq 'm.room.message', "second peek has message type" ); + assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something else to peek', "second peek has message body" ); + + Future->done(1) + }) + }; + +# test "Users can re-peek into world-readable remote rooms" + +# test "Users cannot peek into remote rooms with non-world-readable history visibility" + +# test "Peeking uses server_name to specify the peeking server" + +# test "Peeking into an unknown room returns the right error" + +# test "Server implements PUT /peek over federation correctly" + +# test "Server implements DELETE /peek over federation correctly" + +# test "If a peek is not renewed, the peeked server stops sending events" + +# test "Server can't peek into unknown room versions" \ No newline at end of file From 3cbfa9d8102926d429647dfc63097b928b5e5e20 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 13 Sep 2020 00:16:32 +0100 Subject: [PATCH 3/9] more test ideas --- tests/50federation/44peeking.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/50federation/44peeking.pl b/tests/50federation/44peeking.pl index 0487129bc..5a28a9d15 100644 --- a/tests/50federation/44peeking.pl +++ b/tests/50federation/44peeking.pl @@ -74,6 +74,10 @@ # test "Users cannot peek into remote rooms with non-world-readable history visibility" +# test "Remote peeks are cancelled if a room's history visibility changes to non-world-readable" + +# test "Joining a peeked remote room moves it atomically from peeked to joined rooms" + # test "Peeking uses server_name to specify the peeking server" # test "Peeking into an unknown room returns the right error" @@ -84,4 +88,7 @@ # test "If a peek is not renewed, the peeked server stops sending events" -# test "Server can't peek into unknown room versions" \ No newline at end of file +# test "Server can't peek into unknown room versions" + +# test "Can't peek if server-ACL'd" + From e7560107886792a42856db2650de19aeef44006b Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 23 Sep 2020 00:06:21 +0100 Subject: [PATCH 4/9] derace setting hist viz --- tests/31sync/17peeking.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/31sync/17peeking.pl b/tests/31sync/17peeking.pl index 470453c48..31eab0cd0 100644 --- a/tests/31sync/17peeking.pl +++ b/tests/31sync/17peeking.pl @@ -9,7 +9,7 @@ check => sub { my ( $user, $room_id, $peeking_user ) = @_; - matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub { + matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub { do_request_json_for( $peeking_user, method => "POST", uri => "/r0/peek/$room_id", @@ -85,7 +85,7 @@ check => sub { my ( $user, $room_id, $peeking_user ) = @_; - matrix_set_room_history_visibility( $user, $room_id, $visibility )->then(sub { + matrix_set_room_history_visibility_synced( $user, $room_id, $visibility )->then(sub { do_request_json_for( $peeking_user, method => "POST", uri => "/r0/peek/$room_id", @@ -113,7 +113,7 @@ check => sub { my ( $user, $room_id, $peeking_user ) = @_; - matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub { + matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub { do_request_json_for( $peeking_user, method => "POST", uri => "/r0/peek/#$room_alias_name:".$user->http->server_name, @@ -149,7 +149,7 @@ my ( $user, $room_id, $peeking_user ) = @_; my ( $peeking_user_device2 ); - matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub { + matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub { matrix_login_again_with_user($peeking_user); })->then(sub { $peeking_user_device2 = $_[0]; From 4915543a0262a3ed15a618e0a074f4f0080e7ab1 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 23 Sep 2020 00:06:45 +0100 Subject: [PATCH 5/9] fix test --- tests/50federation/44peeking.pl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/50federation/44peeking.pl b/tests/50federation/44peeking.pl index 5a28a9d15..4f9f8a733 100644 --- a/tests/50federation/44peeking.pl +++ b/tests/50federation/44peeking.pl @@ -10,15 +10,15 @@ check => sub { my ( $user, $room_id, $peeking_user ) = @_; - matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub { + matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub { + matrix_send_room_text_message_synced( $user, $room_id, body => "something to peek"); + })->then(sub { do_request_json_for( $peeking_user, method => "POST", uri => "/r0/peek/#$room_alias_name:".$user->http->server_name, content => {}, ) })->then( sub { - matrix_send_room_text_message_synced( $user, $room_id, body => "something to peek"); - })->then(sub { await_sync( $peeking_user, since => $peeking_user->sync_next_batch, check => sub { @@ -39,10 +39,9 @@ assert_json_keys( $room->{state}, qw( events )); assert_json_keys( $room->{ephemeral}, qw( events )); - assert_ok( $room->{timeline}->{events}->[0]->{type} eq 'm.room.create', "peek has m.room.create" ); + assert_ok( (grep { $_->{type} eq 'm.room.create' } @{$room->{state}->{events}}), "peek has m.room.create in state" ); assert_ok( $room->{timeline}->{events}->[-1]->{type} eq 'm.room.message', "peek has message type" ); assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something to peek', "peek has message body" ); - assert_ok( @{$room->{state}->{events}} == 0 ); assert_ok( scalar keys(%{$body->{rooms}{join}}) == 0, "no joined rooms present"); })->then( sub { From 9162ac89d1d7066a13c9fc294197dd1b0f61ddeb Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 27 Sep 2020 00:29:17 +0100 Subject: [PATCH 6/9] deflake by syncing until we have a timeline when peeking over fed --- tests/50federation/44peeking.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/50federation/44peeking.pl b/tests/50federation/44peeking.pl index 4f9f8a733..d048d8297 100644 --- a/tests/50federation/44peeking.pl +++ b/tests/50federation/44peeking.pl @@ -23,7 +23,7 @@ since => $peeking_user->sync_next_batch, check => sub { my ( $body ) = @_; - return 0 unless $body->{rooms}{peek}{$room_id}; + return 0 unless $body->{rooms}{peek}{$room_id} && @{$body->{rooms}{peek}{$room_id}{timeline}{events}}; return $body; } ) From 5efae21265e70272936ca0b9581a471c4aae2f7a Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 27 Sep 2020 00:29:18 +0100 Subject: [PATCH 7/9] deflake by syncing until we have a timeline when peeking over fed --- lib/SyTest/Homeserver/Dendrite.pm | 2 +- lib/SyTest/Homeserver/ProcessManager.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/SyTest/Homeserver/Dendrite.pm b/lib/SyTest/Homeserver/Dendrite.pm index 75d2d472a..c5a234258 100644 --- a/lib/SyTest/Homeserver/Dendrite.pm +++ b/lib/SyTest/Homeserver/Dendrite.pm @@ -90,7 +90,7 @@ sub _get_config 'postgresql://%s:%s@%s/%s?sslmode=%s', $db_config{args}->{user}, $db_config{args}->{password}, - "", # $db_config{args}->{host}, + $db_config{args}->{host}, $db_config{args}->{database}, $db_config{args}->{sslmode}, ); diff --git a/lib/SyTest/Homeserver/ProcessManager.pm b/lib/SyTest/Homeserver/ProcessManager.pm index 4aa3c9b0f..ad1d84849 100644 --- a/lib/SyTest/Homeserver/ProcessManager.pm +++ b/lib/SyTest/Homeserver/ProcessManager.pm @@ -109,7 +109,7 @@ sub _on_output_line my ( $proc_info, $line ) = @_; push @{ $proc_info->output_lines }, $line; - shift @{ $proc_info->output_lines } while @{ $proc_info->output_lines } > 20; + shift @{ $proc_info->output_lines } while @{ $proc_info->output_lines } > 2000; if( $proc_info->print_output ) { print STDERR "\e[1;35m[server]\e[m: $line\n"; From 4eca974209cff906ccacd559e117b7f5d1d46e24 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 27 Sep 2020 00:29:48 +0100 Subject: [PATCH 8/9] oops --- lib/SyTest/Homeserver/ProcessManager.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SyTest/Homeserver/ProcessManager.pm b/lib/SyTest/Homeserver/ProcessManager.pm index ad1d84849..4aa3c9b0f 100644 --- a/lib/SyTest/Homeserver/ProcessManager.pm +++ b/lib/SyTest/Homeserver/ProcessManager.pm @@ -109,7 +109,7 @@ sub _on_output_line my ( $proc_info, $line ) = @_; push @{ $proc_info->output_lines }, $line; - shift @{ $proc_info->output_lines } while @{ $proc_info->output_lines } > 2000; + shift @{ $proc_info->output_lines } while @{ $proc_info->output_lines } > 20; if( $proc_info->print_output ) { print STDERR "\e[1;35m[server]\e[m: $line\n"; From 3186abd46cbbde1bc3f06aefb94007b43d7ab1fb Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 27 Sep 2020 20:58:17 +0100 Subject: [PATCH 9/9] explain the flakiness --- tests/50federation/44peeking.pl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/50federation/44peeking.pl b/tests/50federation/44peeking.pl index d048d8297..a4ec6d038 100644 --- a/tests/50federation/44peeking.pl +++ b/tests/50federation/44peeking.pl @@ -12,6 +12,9 @@ matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub { matrix_send_room_text_message_synced( $user, $room_id, body => "something to peek"); + # XXX: this is flakey because we don't yet atomically /send events after starting /peeking, + # so if the /peek executes after the peeked server has already processed the event at the point + # of the peek, then we'll never receive it. })->then(sub { do_request_json_for( $peeking_user, method => "POST",