Skip to content

Commit

Permalink
Fix flakiness due to create_room_synced (#702)
Browse files Browse the repository at this point in the history
When we create a room, it's possible for a subsequent /sync to receive subset of
the intial events in that room. This was making some tests [1] flaky when
running in worker mode.

AFAICT there's nothing in the spec which forbids this behaviour. By way of a
workaround, we send a test message in the new room and wait for it to turn up
over /sync.

However, a corollary is that we can't rely on the /sync to contain all the
events in the room. Solution to that is to sync again in tests that actually
care about the sync body.

[1]: notably 'A message sent after an initial sync appears in the timeline of
an incremental sync.'
  • Loading branch information
richvdh authored Sep 12, 2019
1 parent a443af5 commit abec934
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
62 changes: 44 additions & 18 deletions tests/10apidoc/30room-create.pl
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,17 @@
do => sub {
my ( $user ) = @_;

my $room_id;

matrix_create_room_synced(
$user,
room_version => '2',
)->then( sub {
my ( $room_id, undef, $sync_body ) = @_;
( $room_id ) = @_;

matrix_sync( $user );
})->then( sub {
my ( $sync_body ) = @_;

log_if_fail "sync body", $sync_body;

Expand All @@ -188,7 +194,7 @@
do => sub {
my ( $user ) = @_;

matrix_create_room_synced(
matrix_create_room(
$user,
room_version => 1,
)->main::expect_http_400()
Expand All @@ -207,7 +213,7 @@
do => sub {
my ( $user ) = @_;

matrix_create_room_synced(
matrix_create_room(
$user,
room_version => "agjkyhdsghkjackljkj",
)->main::expect_http_400()
Expand All @@ -225,14 +231,20 @@
do => sub {
my ( $user ) = @_;

my $room_id;

matrix_create_room_synced(
$user,
creation_content => {
test => "azerty",
room_version => "test",
},
)->then( sub {
my ( $room_id, undef, $sync_body ) = @_;
( $room_id ) = @_;

matrix_sync( $user );
})->then( sub {
my ( $sync_body ) = @_;

log_if_fail "sync body", $sync_body;

Expand Down Expand Up @@ -377,31 +389,45 @@ sub room_alias_fixture
=head2 matrix_create_room_synced
matrix_create_room_synced( $creator, %params )->then( sub {
my ( $room_id, $room_alias, $sync_body ) = @_;
my ( $room_id ) = @_;
});
Creates a new room, and waits for it to appear in the /sync response.
The parameters are passed through to C<matrix_create_room>.
The resultant future completes with three values: the room_id from the
/createRoom response; the room_alias from the /createRoom response (which is
non-standard and should not be relied upon); the /sync response.
The resultant future completes with the room_id.
=cut

sub matrix_create_room_synced
{
my ( $user, %params ) = @_;

matrix_do_and_wait_for_sync( $user,
do => sub {
matrix_create_room( $user, %params );
},
check => sub {
my ( $sync_body, $room_id ) = @_;
return 0 if not exists $sync_body->{rooms}{join}{$room_id};
return $sync_body;
},
);
# we want to make sure we have all of the room-creation events before we return.
# The easiest way to do that is to send a sentinel message in the room and wait for
# that to turn up.
matrix_create_room( $user, %params )->then( sub {
my ( $room_id ) = @_;

matrix_do_and_wait_for_sync( $user,
do => sub {
my $uri = "/r0/rooms/$room_id/send/m.room.test";

do_request_json_for(
$user,
method => "POST",
uri => $uri,
content => {},
);
},
check => sub {
my ( $sync_body, $send_body ) = @_;
my $event_id = $send_body->{event_id};
return sync_timeline_contains( $sync_body, $room_id, sub {
$_[0]->{event_id} eq $event_id
});
},
)->then_done( $room_id );
});
}
14 changes: 11 additions & 3 deletions tests/32room-versions.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
check => sub {
my ( $user ) = @_;

my $room_id;

matrix_create_room_synced(
$user,
room_version => $version,
)->then( sub {
my ( $room_id, undef, $sync_body ) = @_;
( $room_id ) = @_;

matrix_sync( $user );
})->then( sub {
my ( $sync_body ) = @_;

log_if_fail "sync body", $sync_body;

Expand Down Expand Up @@ -42,14 +48,16 @@
check => sub {
my ( $user, $joiner, $room_alias_name ) = @_;

my ( $room_id, $room_alias, $event_id );
my ( $room_id, $event_id );

my $room_alias = sprintf( '#%s:%s', $room_alias_name, $user->server_name );

matrix_create_room_synced(
$user,
room_version => $version,
room_alias_name => $room_alias_name,
)->then( sub {
( $room_id, $room_alias ) = @_;
( $room_id ) = @_;

matrix_join_room_synced( $joiner, $room_alias );
})->then( sub {
Expand Down

0 comments on commit abec934

Please sign in to comment.