From d8d4822052efe2cf176dd86538d4a1dad179e4ae Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Tue, 28 Jun 2022 12:37:01 +0200 Subject: [PATCH 1/3] Don't require an "end" key --- tests/10apidoc/34room-messages.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/10apidoc/34room-messages.pl b/tests/10apidoc/34room-messages.pl index 4a9554add..3916c4e87 100644 --- a/tests/10apidoc/34room-messages.pl +++ b/tests/10apidoc/34room-messages.pl @@ -158,7 +158,7 @@ sub matrix_send_room_text_message })->then( sub { my ( $body ) = @_; - assert_json_keys( $body, qw( start end chunk )); + assert_json_keys( $body, qw( start chunk )); assert_json_list( $body->{chunk} ); scalar @{ $body->{chunk} } > 0 or @@ -198,7 +198,7 @@ sub matrix_send_room_text_message log_if_fail "Body", $body; - assert_json_keys( $body, qw( start end state chunk )); + assert_json_keys( $body, qw( start state chunk )); assert_json_list( $body->{chunk} ); assert_json_list( $body->{state} ); From 1b316f770c8efe5d6d987f6230f25fdaabfa3088 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Tue, 28 Jun 2022 19:21:51 +0200 Subject: [PATCH 2/3] Extend tests to verify "end" is missing, if there are no more events --- tests/10apidoc/34room-messages.pl | 55 +++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/tests/10apidoc/34room-messages.pl b/tests/10apidoc/34room-messages.pl index b9f9fd935..55ba5aacd 100644 --- a/tests/10apidoc/34room-messages.pl +++ b/tests/10apidoc/34room-messages.pl @@ -136,6 +136,7 @@ sub matrix_send_room_text_message check => sub { my ( $user, $room_id ) = @_; + my $token; matrix_send_room_text_message_synced( $user, $room_id, body => "Here is the message content", @@ -143,8 +144,7 @@ sub matrix_send_room_text_message matrix_sync( $user ) })->then( sub { my ( $sync_body ) = @_; - my $token = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch}; - + $token = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch}; do_request_json_for( $user, method => "GET", uri => "/v3/rooms/$room_id/messages", @@ -158,12 +158,33 @@ sub matrix_send_room_text_message })->then( sub { my ( $body ) = @_; - assert_json_keys( $body, qw( start chunk )); + # We should still get events and a "end" key, check it is actually there + assert_json_keys( $body, qw( start end chunk )); assert_json_list( $body->{chunk} ); + $token = $body->{end}; scalar @{ $body->{chunk} } > 0 or die "Expected some messages but got none at all\n"; + })->then( sub { + # Do another call to /messages, this time we don't expect to receive a "end" key + do_request_json_for( $user, + method => "GET", + uri => "/v3/rooms/$room_id/messages", + + # With no params this does "forwards from END"; i.e. nothing useful + params => { + dir => "b", + from => $token, + }, + ) + })->then( sub { + my ( $body ) = @_; + + assert_json_keys( $body, qw( start chunk )); + if( exists $body->{end} ) { + die "Unexpected 'end' key in response" + } Future->done(1); }); }; @@ -174,6 +195,7 @@ sub matrix_send_room_text_message check => sub { my ( $user, $room_id ) = @_; + my $token; matrix_send_room_text_message_synced( $user, $room_id, body => "Here is the message content", @@ -181,7 +203,7 @@ sub matrix_send_room_text_message matrix_sync( $user ) })->then( sub { my ( $sync_body ) = @_; - my $token = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch}; + $token = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch}; do_request_json_for( $user, method => "GET", @@ -197,10 +219,12 @@ sub matrix_send_room_text_message my ( $body ) = @_; log_if_fail "Body", $body; - - assert_json_keys( $body, qw( start state chunk )); + + # We should still get events and a "end" key, check it is actually there + assert_json_keys( $body, qw( start end state chunk )); assert_json_list( $body->{chunk} ); assert_json_list( $body->{state} ); + $token = $body->{end}; assert_eq( scalar @{$body->{state}}, 1); assert_eq( $body->{state}[0]{type}, 'm.room.member'); @@ -209,6 +233,25 @@ sub matrix_send_room_text_message scalar @{ $body->{chunk} } > 0 or die "Expected some messages but got none at all\n"; + })->then( sub { + # Do another call to /messages, this time we don't expect to receive a "end" key + do_request_json_for( $user, + method => "GET", + uri => "/v3/rooms/$room_id/messages", + + # With no params this does "forwards from END"; i.e. nothing useful + params => { + dir => "b", + from => $token, + }, + ) + })->then( sub { + my ( $body ) = @_; + + assert_json_keys( $body, qw( start chunk )); + if( exists $body->{end} ) { + die "Unexpected 'end' key in response" + } Future->done(1); }); }; From 6ccdc6b18207136337d1199378f875fc5e899573 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Thu, 30 Jun 2022 09:49:03 +0200 Subject: [PATCH 3/3] Update comments --- tests/10apidoc/34room-messages.pl | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/10apidoc/34room-messages.pl b/tests/10apidoc/34room-messages.pl index 55ba5aacd..b83c47eee 100644 --- a/tests/10apidoc/34room-messages.pl +++ b/tests/10apidoc/34room-messages.pl @@ -158,7 +158,7 @@ sub matrix_send_room_text_message })->then( sub { my ( $body ) = @_; - # We should still get events and a "end" key, check it is actually there + # We should still get events and a "end" key: check they are actually there assert_json_keys( $body, qw( start end chunk )); assert_json_list( $body->{chunk} ); $token = $body->{end}; @@ -166,13 +166,10 @@ sub matrix_send_room_text_message scalar @{ $body->{chunk} } > 0 or die "Expected some messages but got none at all\n"; })->then( sub { - - # Do another call to /messages, this time we don't expect to receive a "end" key + # Do another call to /messages. This time we don't expect to receive a "end" key do_request_json_for( $user, method => "GET", uri => "/v3/rooms/$room_id/messages", - - # With no params this does "forwards from END"; i.e. nothing useful params => { dir => "b", from => $token, @@ -220,7 +217,7 @@ sub matrix_send_room_text_message log_if_fail "Body", $body; - # We should still get events and a "end" key, check it is actually there + # We should still get events and a "end" key: check they are actually there assert_json_keys( $body, qw( start end state chunk )); assert_json_list( $body->{chunk} ); assert_json_list( $body->{state} ); @@ -234,12 +231,10 @@ sub matrix_send_room_text_message die "Expected some messages but got none at all\n"; })->then( sub { - # Do another call to /messages, this time we don't expect to receive a "end" key + # Do another call to /messages. This time we don't expect to receive a "end" key do_request_json_for( $user, method => "GET", uri => "/v3/rooms/$room_id/messages", - - # With no params this does "forwards from END"; i.e. nothing useful params => { dir => "b", from => $token,