Skip to content

Commit

Permalink
test to ensure spurious state doesn't leak into incr sync responses w…
Browse files Browse the repository at this point in the history
…hen LLing

tests matrix-org/synapse#3760
regression test for element-hq/element-web#7223
  • Loading branch information
ara4n committed Aug 24, 2018
1 parent 8785bfa commit db41807
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
30 changes: 29 additions & 1 deletion tests/10apidoc/09synced.pl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,35 @@ sub await_sync_presence_contains {
}


push @EXPORT, qw( assert_room_members assert_state_room_members_matches );
push @EXPORT, qw( assert_room_members assert_state_room_members_matches assert_room_state);

# assert that the state body of a sync response is made up of the given state types.
sub assert_room_state {
my ( $body, $room_id, $state_types ) = @_;

my $room = $body->{rooms}{join}{$room_id};
my $state = $room->{state}{events};

log_if_fail "Room", $room;

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

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

$found_types = [ sort { &$comp($a, $b) } @$found_types ];
$state_types = [ sort { &$comp($a, $b) } @$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);
}

# assert that the given members are in the body of a sync response
sub assert_room_members {
Expand Down
14 changes: 11 additions & 3 deletions tests/31sync/15lazy-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@
matrix_sync( $alice, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;
assert_room_members( $body, $room_id, [ $bob->user_id ]);
assert_room_state( $body, $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 +177,9 @@
matrix_sync_again( $alice, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;
assert_room_members( $body, $room_id, [ $charlie->user_id ]);
assert_room_state( $body, $room_id, [
[ 'm.room.member', $charlie->user_id ],
]);
Future->done(1);
});
};
Expand Down Expand Up @@ -258,7 +267,6 @@
});
};


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

0 comments on commit db41807

Please sign in to comment.