diff --git a/tests/10apidoc/03events-initial.pl b/tests/10apidoc/03events-initial.pl index ba77fa2b3..de4662082 100644 --- a/tests/10apidoc/03events-initial.pl +++ b/tests/10apidoc/03events-initial.pl @@ -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 { diff --git a/tests/30rooms/30history-visibility.pl b/tests/30rooms/30history-visibility.pl index 7351316c2..f6c86bbce 100644 --- a/tests/30rooms/30history-visibility.pl +++ b/tests/30rooms/30history-visibility.pl @@ -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 { @@ -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 diff --git a/tests/90jira/SYN-606.pl b/tests/90jira/SYN-606.pl index 5845fd426..173a0c7c2 100644 --- a/tests/90jira/SYN-606.pl +++ b/tests/90jira/SYN-606.pl @@ -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 ) = @_; @@ -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 ) );