Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test to ensure spurious state doesn't leak into incr sync responses when LLing #487

Merged
merged 6 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions tests/10apidoc/09synced.pl
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,52 @@ sub await_sync_presence_contains {
}


push @EXPORT, qw( assert_room_members assert_state_room_members_matches );
=head2 assert_state_types_match

Assert that the state body of a sync response is made up of the given state types.

$state is an arrayref of state events.

$state_types is an arrayref of arrayrefs, each a tuple of type & state_key.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an example might have been helpful.


=cut

push @EXPORT, qw( assert_state_types_match );

sub assert_state_types_match {
my ( $state, $room_id, $state_types ) = @_;

my $found_types = [];
foreach (@$state) {
push @$found_types, [ $_->{type}, $_->{state_key} ];
}

my $comp = sub {
return ($a->[0] cmp $b->[0]) || ($a->[1] cmp $b->[1]);
};

$found_types = [ sort $comp @$found_types ];
$state_types = [ sort $comp @$state_types ];

log_if_fail "Found state types", $found_types;
log_if_fail "Desired state types", $state_types;

assert_deeply_eq($found_types, $state_types);
}

=head2 assert_room_members

Assert that the given members are in the body of a sync response

$memberships is either an arrayref of user_ids or a hashref of user_id
to membership strings.

=cut

push @EXPORT, qw ( assert_room_members );

# assert that the given members are in the body of a sync response
sub assert_room_members {
my ( $body, $room_id, $memberships ) = @_;
# Takes either an arrayref of user_ids or a hashref of user_id to membership strings

my $room = $body->{rooms}{join}{$room_id};
my $timeline = $room->{timeline}{events};
Expand All @@ -219,14 +259,22 @@ sub assert_room_members {

assert_json_keys( $room, qw( timeline state ephemeral ));

return assert_state_room_members_matches( $room->{state}{events}, $memberships );
return assert_state_room_members_match( $room->{state}{events}, $memberships );
}

=head2 assert_state_room_members_match

Assert that the given members are present in a block of state events

$memberships is either an arrayref of user_ids or a hashref of user_id
to membership strings.

=cut

push @EXPORT, qw( assert_state_room_members_match );

# assert that the given members are present in a block of state events
sub assert_state_room_members_matches {
sub assert_state_room_members_match {
my ( $events, $memberships ) = @_;
# Takes either an arrayref of user_ids or a hashref of user_id to membership strings

log_if_fail "expected members:", $memberships;
log_if_fail "state:", $events;
Expand Down
2 changes: 1 addition & 1 deletion tests/30rooms/50context.pl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
assert_json_keys( $body, qw( state event ) );

# only the user who sent 'hello world' should be present in the state
assert_state_room_members_matches( $body->{state}, [ $user->user_id ]);
assert_state_room_members_match( $body->{state}, [ $user->user_id ]);

Future->done( 1 )
});
Expand Down
10 changes: 5 additions & 5 deletions tests/30rooms/52members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

assert_json_keys( $body, qw( chunk ) );

assert_state_room_members_matches( $body->{chunk}, [
assert_state_room_members_match( $body->{chunk}, [
$user1->user_id,
$user2->user_id,
]);
Expand Down Expand Up @@ -69,7 +69,7 @@
assert_json_keys( $body, qw( chunk ) );

# as of the first 'Hello world' the only member in the room should be user1
assert_state_room_members_matches( $body->{chunk}, [ $user1->user_id ]);
assert_state_room_members_match( $body->{chunk}, [ $user1->user_id ]);

Future->done(1);
})
Expand Down Expand Up @@ -100,7 +100,7 @@
my ( $body ) = @_;

assert_json_keys( $body, qw( chunk ) );
assert_state_room_members_matches( $body->{chunk}, { $user1->user_id => 'join' } );
assert_state_room_members_match( $body->{chunk}, { $user1->user_id => 'join' } );

do_request_json_for( $user1,
method => "GET",
Expand All @@ -113,7 +113,7 @@
my ( $body ) = @_;

assert_json_keys( $body, qw( chunk ) );
assert_state_room_members_matches( $body->{chunk}, { $user2->user_id => 'leave' });
assert_state_room_members_match( $body->{chunk}, { $user2->user_id => 'leave' });

do_request_json_for( $user1,
method => "GET",
Expand All @@ -126,7 +126,7 @@
my ( $body ) = @_;

assert_json_keys( $body, qw( chunk ) );
assert_state_room_members_matches( $body->{chunk}, { $user1->user_id => 'join' });
assert_state_room_members_match( $body->{chunk}, { $user1->user_id => 'join' });
Future->done(1);
})
};
Expand Down
18 changes: 15 additions & 3 deletions tests/31sync/15lazy-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,16 @@
matrix_sync( $alice, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;
assert_room_members( $body, $room_id, [ $bob->user_id ]);
my $state = $body->{rooms}{join}{$room_id}{state}{events};

assert_state_types_match( $state, $room_id, [
[ 'm.room.create', '' ],
[ 'm.room.join_rules', '' ],
[ 'm.room.power_levels', '' ],
[ 'm.room.name', '' ],
[ 'm.room.history_visibility', '' ],
[ 'm.room.member', $bob->user_id ],
]);

matrix_send_room_text_message_synced( $charlie, $room_id,
body => "Message from charlie",
Expand All @@ -170,7 +179,11 @@
matrix_sync_again( $alice, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;
assert_room_members( $body, $room_id, [ $charlie->user_id ]);
my $state = $body->{rooms}{join}{$room_id}{state}{events};

assert_state_types_match( $state, $room_id, [
[ 'm.room.member', $charlie->user_id ],
]);
Future->done(1);
});
};
Expand Down Expand Up @@ -258,7 +271,6 @@
});
};


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is inconsistent...

test "We don't send redundant membership state across incremental syncs by default",
requires => [ local_user_fixtures( 3 ),
qw( can_sync ) ],
Expand Down