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

Fix flakiness due to create_room_synced #702

Merged
merged 1 commit into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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: 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