From 068187669b6158f0d3bab4956dceea5bff92d4f4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 29 Oct 2019 10:45:36 +0000 Subject: [PATCH 1/3] Tests room dir search --- tests/30rooms/70publicroomslist.pl | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/30rooms/70publicroomslist.pl b/tests/30rooms/70publicroomslist.pl index b8eff0553..34f0af6fb 100644 --- a/tests/30rooms/70publicroomslist.pl +++ b/tests/30rooms/70publicroomslist.pl @@ -248,3 +248,44 @@ Future->done( 1 ); }) }; + +test "Can search public room list", + requires => [ $main::HOMESERVER_INFO[0], local_user_fixture() ], + + check => sub { + my ( $info, $local_user ) = @_; + + my $room_id; + + matrix_create_room( $local_user, + visibility => "public", + name => "Test Name", + topic => "Test Topic Wombles", + )->then( sub { + ( $room_id ) = @_; + + do_request_json_for( $local_user, + method => "POST", + uri => "/r0/publicRooms", + + content => { + filter => { + generic_search_term => "wombles", # Search case insesitively + } + }, + ) + })->then( sub { + my ( $body ) = @_; + + log_if_fail "Body", $body; + + assert_json_keys( $body, qw( chunk ) ); + + # We only expect to find a single result + assert_eq( scalar @{ $body->{chunk} }, 1 ); + + assert_eq( $body->{chunk}[0]{room_id}, $room_id ); + + Future->done( 1 ); + }) + }; From 0b009ceaf2fec56edcc8a0015b548a306f79d990 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 29 Oct 2019 11:12:36 +0000 Subject: [PATCH 2/3] Wrap in retry loop as room dir is updated async --- tests/30rooms/70publicroomslist.pl | 36 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/30rooms/70publicroomslist.pl b/tests/30rooms/70publicroomslist.pl index 34f0af6fb..000fa574d 100644 --- a/tests/30rooms/70publicroomslist.pl +++ b/tests/30rooms/70publicroomslist.pl @@ -264,28 +264,30 @@ )->then( sub { ( $room_id ) = @_; - do_request_json_for( $local_user, - method => "POST", - uri => "/r0/publicRooms", + retry_until_success { + do_request_json_for( $local_user, + method => "POST", + uri => "/r0/publicRooms", - content => { - filter => { - generic_search_term => "wombles", # Search case insesitively - } - }, - ) - })->then( sub { - my ( $body ) = @_; + content => { + filter => { + generic_search_term => "wombles", # Search case insesitively + } + }, + )->then( sub { + my ( $body ) = @_; - log_if_fail "Body", $body; + log_if_fail "Body", $body; - assert_json_keys( $body, qw( chunk ) ); + assert_json_keys( $body, qw( chunk ) ); - # We only expect to find a single result - assert_eq( scalar @{ $body->{chunk} }, 1 ); + # We only expect to find a single result + assert_eq( scalar @{ $body->{chunk} }, 1 ); - assert_eq( $body->{chunk}[0]{room_id}, $room_id ); + assert_eq( $body->{chunk}[0]{room_id}, $room_id ); - Future->done( 1 ); + Future->done( 1 ); + }) + } }) }; From 2dc573eae716a9fa1c0a3ae35a2b211239f9f1df Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 31 Oct 2019 14:29:03 +0000 Subject: [PATCH 3/3] Review comments --- tests/30rooms/70publicroomslist.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/30rooms/70publicroomslist.pl b/tests/30rooms/70publicroomslist.pl index 000fa574d..18d1a43ef 100644 --- a/tests/30rooms/70publicroomslist.pl +++ b/tests/30rooms/70publicroomslist.pl @@ -274,7 +274,7 @@ generic_search_term => "wombles", # Search case insesitively } }, - )->then( sub { + )->then( sub { my ( $body ) = @_; log_if_fail "Body", $body; @@ -283,11 +283,14 @@ # We only expect to find a single result assert_eq( scalar @{ $body->{chunk} }, 1 ); - assert_eq( $body->{chunk}[0]{room_id}, $room_id ); Future->done( 1 ); - }) + })->on_fail( sub { + my ( $exc ) = @_; + chomp $exc; + log_if_fail "Failed to search room dir: $exc"; + }); } }) };