From 8fd5dea74e04a45aabdfae306631993da7fdd1f9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 7 Apr 2016 15:50:35 +0100 Subject: [PATCH 1/5] WIP test for push badges. This doesn't work because the check for the zero badge push looks like it's getting the content from the previous poke. Inspecting the pokes with -C, I can see they're correct. There are also more lost sequence futures than normal I think. --- tests/61push/01message-pushed.pl | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/61push/01message-pushed.pl b/tests/61push/01message-pushed.pl index 3e69f8d0e..35987613c 100644 --- a/tests/61push/01message-pushed.pl +++ b/tests/61push/01message-pushed.pl @@ -40,10 +40,20 @@ })->SyTest::pass_on_done( "Bob received invite" ), matrix_invite_user_to_room( $alice, $bob, $room_id ), + flush_events_for( $alice ), ) })->then( sub { # Bob accepts the invite by joining the room matrix_join_room( $bob, $room_id ) + })->then( sub { + await_event_for( $alice, filter => sub { + my ( $event ) = @_; + pass "got event"; + matrix_advance_room_receipt( $alice, $room_id, + "m.read" => $event->{event_id} + ); + return 1; + }); })->then( sub { # Now that Bob has joined the room, we will create a pusher for # Alice. This may race with Bob joining the room. So the first @@ -101,6 +111,7 @@ assert_json_keys( $notification->{counts}, qw( unread )); + assert_eq( $notification->{counts}->{unread}, 1, "unread count"); assert_json_keys( $notification->{devices}[0], qw( app_id pushkey pushkey_ts data tweaks )); @@ -112,6 +123,38 @@ die "Unexpected message body"; pass "Alice was pushed"; # Alice has gone down the stairs + + Future->needs_all( + await_http_request( "/alice_push", sub { + my ( $request ) = @_; + my $body = $request->body_from_json; + + return unless $body->{notification}{counts}; + return 1; + })->then( sub { + my ( $request ) = @_; + + $request->respond( HTTP::Response->new( 200, "OK", [], "" ) ); + Future->done( $request ); + }), + + # Now send a read receipt for that message + matrix_advance_room_receipt( $alice, $notification->{room_id}, + "m.read" => $notification->{event_id} + )->SyTest::pass_on_done( "Receipt sent" ), + ) + })->then( sub { + my ( $request ) = @_; + my $body = $request->body_from_json; + my $notification = $body->{notification}; + + assert_json_keys( $notification->{counts}, qw( + unread + )); + assert_eq( $notification->{counts}->{unread}, 1, "unread count"); + + pass "Zero badge push received"; + Future->done(1); }); }; From 9d365f2785cbdd41a73536b8bccde7a1cdd3f696 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 7 Apr 2016 16:05:40 +0100 Subject: [PATCH 2/5] remove debugging --- tests/61push/01message-pushed.pl | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/61push/01message-pushed.pl b/tests/61push/01message-pushed.pl index 35987613c..d1013352c 100644 --- a/tests/61push/01message-pushed.pl +++ b/tests/61push/01message-pushed.pl @@ -48,7 +48,6 @@ })->then( sub { await_event_for( $alice, filter => sub { my ( $event ) = @_; - pass "got event"; matrix_advance_room_receipt( $alice, $room_id, "m.read" => $event->{event_id} ); From 0e994fac5fe93495ee5b29deaa1f0c319e64dc93 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 7 Apr 2016 16:21:38 +0100 Subject: [PATCH 3/5] Make correct assertion & send receipt correctly Turns out I was just confused and asserting the wrong thing. Also this changes the await_event so we wait for the receipt to be sent before continuing. --- tests/61push/01message-pushed.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/61push/01message-pushed.pl b/tests/61push/01message-pushed.pl index d1013352c..5652fc4d8 100644 --- a/tests/61push/01message-pushed.pl +++ b/tests/61push/01message-pushed.pl @@ -47,11 +47,12 @@ matrix_join_room( $bob, $room_id ) })->then( sub { await_event_for( $alice, filter => sub { + return 1; + })->then( sub { my ( $event ) = @_; matrix_advance_room_receipt( $alice, $room_id, "m.read" => $event->{event_id} ); - return 1; }); })->then( sub { # Now that Bob has joined the room, we will create a pusher for @@ -102,7 +103,7 @@ my ( $request ) = @_; my $body = $request->body_from_json; - log_if_fail "Request body", $body; + log_if_fail "Message push request body", $body; assert_json_keys( my $notification = $body->{notification}, qw( id room_id type sender content devices counts @@ -147,10 +148,12 @@ my $body = $request->body_from_json; my $notification = $body->{notification}; + log_if_fail "Zero badge push request body", $body; + assert_json_keys( $notification->{counts}, qw( unread )); - assert_eq( $notification->{counts}->{unread}, 1, "unread count"); + assert_eq( $notification->{counts}{unread}, 0, "unread count"); pass "Zero badge push received"; From 23ccb2ad503e60af7ef1e65c8bae562298bb4672 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Apr 2016 15:33:23 +0100 Subject: [PATCH 4/5] Listen explicitly for member events Otherwise we risk flakiness because of getting presence events --- tests/61push/01message-pushed.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/61push/01message-pushed.pl b/tests/61push/01message-pushed.pl index 5652fc4d8..5a51b7689 100644 --- a/tests/61push/01message-pushed.pl +++ b/tests/61push/01message-pushed.pl @@ -47,6 +47,8 @@ matrix_join_room( $bob, $room_id ) })->then( sub { await_event_for( $alice, filter => sub { + my ( $event ) = @_; + return unless $event->{type} eq "m.room.member"; return 1; })->then( sub { my ( $event ) = @_; From 9b47abe68f15d76121a3c80ee4288cd3c95f9382 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Apr 2016 15:35:15 +0100 Subject: [PATCH 5/5] Just respond with empty json Rather than an empty body, since this will set content-length etc for us. Also fix in the place I copied from... --- tests/61push/01message-pushed.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/61push/01message-pushed.pl b/tests/61push/01message-pushed.pl index 5a51b7689..d62e09629 100644 --- a/tests/61push/01message-pushed.pl +++ b/tests/61push/01message-pushed.pl @@ -93,7 +93,7 @@ })->then( sub { my ( $request ) = @_; - $request->respond( HTTP::Response->new( 200, "OK", [], "" ) ); + $request->respond_json( {} ); Future->done( $request ); }), @@ -136,7 +136,7 @@ })->then( sub { my ( $request ) = @_; - $request->respond( HTTP::Response->new( 200, "OK", [], "" ) ); + $request->respond_json( {} ); Future->done( $request ); }),