Skip to content

Commit

Permalink
Merge pull request #421 from matrix-org/erikj/fix_syn_606
Browse files Browse the repository at this point in the history
Fix flakey sytest 80jira/syn606
  • Loading branch information
erikjohnston authored Nov 20, 2017
2 parents a501d4e + ab87f8f commit cf313e7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/10apidoc/03events-initial.pl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ sub GET_new_events_for

return $user->pending_get_events //=
matrix_get_events( $user,
%params,
from => $user->eventstream_token,
timeout => 500,
%params,
)->on_ready( sub {
undef $user->pending_get_events;
})->then( sub {
Expand Down
3 changes: 2 additions & 1 deletion tests/30rooms/30history-visibility.pl
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ sub ignore_presence_for

sub await_event_not_history_visibility_or_presence_for
{
my ( $user, $room_id, $allowed_users ) = @_;
my ( $user, $room_id, $allowed_users, %params ) = @_;
await_event_for( $user,
room_id => $room_id,
filter => sub {
Expand All @@ -590,6 +590,7 @@ sub await_event_not_history_visibility_or_presence_for
return ((not $event->{type} eq "m.presence") or
any { $event->{content}{user_id} eq $_->user_id } @$allowed_users);
},
%params,
)->on_done( sub {
my ( $event ) = @_;
log_if_fail "event", $event
Expand Down
34 changes: 25 additions & 9 deletions tests/90jira/SYN-606.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

test(
"$name user can call /events on another world_readable room (SYN-606)",
requires => [ $fixture->( with_events => 0 ),
local_user_fixture( with_events => 0 ) ],
requires => [ $fixture->(), local_user_fixture() ],

do => sub {
my ( $nonjoined_user, $user ) = @_;
Expand All @@ -27,20 +26,37 @@
})->then( sub {
matrix_initialsync_room( $nonjoined_user, $room_id1 )
})->then( sub {
my ( $body ) = @_;

# We need to manually handle the from tokens here as the await_event*
# methods may otherwise reuse results from an /events call that did
# not include the specified room (due to the user not being joined to
# it). This could cause the event to not be found.
# I.e. there is a race where we send a message, the background /events
# stream streams past the message, and then /events stream triggered by
# await_event_* (which *does* include the room_id) starts streaming
# from *after* the message. Hence the event is neither in the cache
# nor in the live event stream.
my $from_token = $body->{messages}{end};

Future->needs_all(
matrix_send_room_text_message( $user, $room_id1, body => "moose" ),
await_event_not_history_visibility_or_presence_for( $nonjoined_user, $room_id1, [] ),
await_event_not_history_visibility_or_presence_for( $nonjoined_user, $room_id1, [],
from => $from_token,
),
);
})->then( sub {
matrix_initialsync_room( $nonjoined_user, $room_id2 )
})->then( sub {
Future->needs_all(
delay( 0.1 )->then( sub {
matrix_send_room_text_message( $user, $room_id2, body => "mice" );
}),
my ( $body ) = @_;

my $from_token = $body->{messages}{end};

await_event_not_history_visibility_or_presence_for( $nonjoined_user, $room_id2, [] )
->then( sub {
Future->needs_all(
matrix_send_room_text_message( $user, $room_id2, body => "mice" ),
await_event_not_history_visibility_or_presence_for( $nonjoined_user, $room_id2, [],
from => $from_token,
)->then( sub {
my ( $event ) = @_;

assert_json_keys( $event, qw( content ) );
Expand Down

0 comments on commit cf313e7

Please sign in to comment.