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

Handle eventual consistency in public room tests #354

Merged
merged 2 commits into from
May 16, 2017
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
164 changes: 85 additions & 79 deletions tests/30rooms/13guestaccess.pl
Original file line number Diff line number Diff line change
Expand Up @@ -353,55 +353,58 @@
);
}),
)->then( sub {
$http->do_request_json(
method => "GET",
uri => "/r0/publicRooms",
)})->then( sub {
my ( $body ) = @_;

log_if_fail "publicRooms", $body;

assert_json_keys( $body, qw( chunk ));
assert_json_list( $body->{chunk} );

my %seen = (
listingtest0 => 0,
listingtest1 => 0,
listingtest2 => 0,
listingtest3 => 0,
listingtest4 => 0,
);

foreach my $room ( @{ $body->{chunk} } ) {
my $aliases = $room->{aliases};
assert_json_boolean( my $world_readable = $room->{world_readable} );
assert_json_boolean( my $guest_can_join = $room->{guest_can_join} );
try_repeat_until_success( sub {
$http->do_request_json(
method => "GET",
uri => "/r0/publicRooms",
)->then( sub {
my ( $body ) = @_;

foreach my $alias ( @{$aliases} ) {
if( $alias =~ m/^\Q#listingtest0:/ ) {
$seen{listingtest0} = !$world_readable && !$guest_can_join;
}
elsif( $alias =~ m/^\Q#listingtest1:/ ) {
$seen{listingtest1} = $world_readable && !$guest_can_join;
}
elsif( $alias =~ m/^\Q#listingtest2:/ ) {
$seen{listingtest2} = !$world_readable && !$guest_can_join;
}
elsif( $alias =~ m/^\Q#listingtest3:/ ) {
$seen{listingtest3} = !$world_readable && $guest_can_join;
}
elsif( $alias =~ m/^\Q#listingtest4:/ ) {
$seen{listingtest4} = $world_readable && $guest_can_join;
log_if_fail "publicRooms", $body;

assert_json_keys( $body, qw( chunk ));
assert_json_list( $body->{chunk} );

my %seen = (
listingtest0 => 0,
listingtest1 => 0,
listingtest2 => 0,
listingtest3 => 0,
listingtest4 => 0,
);

foreach my $room ( @{ $body->{chunk} } ) {
my $aliases = $room->{aliases};
assert_json_boolean( my $world_readable = $room->{world_readable} );
assert_json_boolean( my $guest_can_join = $room->{guest_can_join} );

foreach my $alias ( @{$aliases} ) {
if( $alias =~ m/^\Q#listingtest0:/ ) {
$seen{listingtest0} = !$world_readable && !$guest_can_join;
}
elsif( $alias =~ m/^\Q#listingtest1:/ ) {
$seen{listingtest1} = $world_readable && !$guest_can_join;
}
elsif( $alias =~ m/^\Q#listingtest2:/ ) {
$seen{listingtest2} = !$world_readable && !$guest_can_join;
}
elsif( $alias =~ m/^\Q#listingtest3:/ ) {
$seen{listingtest3} = !$world_readable && $guest_can_join;
}
elsif( $alias =~ m/^\Q#listingtest4:/ ) {
$seen{listingtest4} = $world_readable && $guest_can_join;
}
}
}
}
}

foreach my $key ( keys %seen ) {
$seen{$key} or die "Wrong for $key";
}
foreach my $key ( keys %seen ) {
$seen{$key} or die "Wrong for $key";
}

Future->done(1);
});
Future->done(1);
})
})
})
};

test "GET /publicRooms includes avatar URLs",
Expand Down Expand Up @@ -444,44 +447,47 @@
);
}),
)->then( sub {
$http->do_request_json(
method => "GET",
uri => "/r0/publicRooms",
)})->then( sub {
my ( $body ) = @_;

log_if_fail "publicRooms", $body;

assert_json_keys( $body, qw( chunk ));
assert_json_list( $body->{chunk} );

my %seen = (
worldreadable => 0,
nonworldreadable => 0,
);

foreach my $room ( @{ $body->{chunk} } ) {
my $aliases = $room->{aliases};
try_repeat_until_success( sub {
$http->do_request_json(
method => "GET",
uri => "/r0/publicRooms",
)->then( sub {
my ( $body ) = @_;

foreach my $alias ( @{$aliases} ) {
if( $alias =~ m/^\Q#worldreadable:/ ) {
assert_json_keys( $room, qw( avatar_url ) );
assert_eq( $room->{avatar_url}, "https://example.com/ringtails.jpg", "avatar_url" );
$seen{worldreadable} = 1;
}
elsif( $alias =~ m/^\Q#nonworldreadable:/ ) {
assert_json_keys( $room, qw( avatar_url ) );
assert_eq( $room->{avatar_url}, "https://example.com/ruffed.jpg", "avatar_url" );
$seen{nonworldreadable} = 1;
log_if_fail "publicRooms", $body;

assert_json_keys( $body, qw( chunk ));
assert_json_list( $body->{chunk} );

my %seen = (
worldreadable => 0,
nonworldreadable => 0,
);

foreach my $room ( @{ $body->{chunk} } ) {
my $aliases = $room->{aliases};

foreach my $alias ( @{$aliases} ) {
if( $alias =~ m/^\Q#worldreadable:/ ) {
assert_json_keys( $room, qw( avatar_url ) );
assert_eq( $room->{avatar_url}, "https://example.com/ringtails.jpg", "avatar_url" );
$seen{worldreadable} = 1;
}
elsif( $alias =~ m/^\Q#nonworldreadable:/ ) {
assert_json_keys( $room, qw( avatar_url ) );
assert_eq( $room->{avatar_url}, "https://example.com/ruffed.jpg", "avatar_url" );
$seen{nonworldreadable} = 1;
}
}
}
}
}

foreach my $key ( keys %seen ) {
$seen{$key} or die "Didn't see $key";
}
foreach my $key ( keys %seen ) {
$seen{$key} or die "Didn't see $key";
}

Future->done(1);
Future->done(1);
})
})
});
};

Expand Down
115 changes: 60 additions & 55 deletions tests/30rooms/70publicroomslist.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use Future::Utils qw( try_repeat_until_success );


test "Name/topic keys are correct",
requires => [ $main::API_CLIENTS[0], local_user_fixture() ],

Expand Down Expand Up @@ -30,72 +33,74 @@
)
} keys %rooms )
->then( sub {
$http->do_request_json(
method => "GET",
uri => "/r0/publicRooms",
)
})->then( sub {
my ( $body ) = @_;

log_if_fail "publicRooms", $body;

assert_json_keys( $body, qw( chunk ));
assert_json_list( $body->{chunk} );

my %seen = map {
$_ => 0,
} keys ( %rooms );

foreach my $room ( @{ $body->{chunk} } ) {
assert_json_keys( $room,
qw( world_readable guest_can_join num_joined_members )
);
try_repeat_until_success( sub {
$http->do_request_json(
method => "GET",
uri => "/r0/publicRooms",
)->then( sub {
my ( $body ) = @_;

log_if_fail "publicRooms", $body;

assert_json_keys( $body, qw( chunk ));
assert_json_list( $body->{chunk} );

my %seen = map {
$_ => 0,
} keys ( %rooms );

foreach my $room ( @{ $body->{chunk} } ) {
assert_json_keys( $room,
qw( world_readable guest_can_join num_joined_members )
);

my $name = $room->{name};
my $topic = $room->{topic};
my $canonical_alias = $room->{canonical_alias};

my $aliases = $room->{aliases};
if( not defined $aliases ) {
next;
}

my $name = $room->{name};
my $topic = $room->{topic};
my $canonical_alias = $room->{canonical_alias};
foreach my $alias ( @{$aliases} ) {
foreach my $alias_local ( keys %rooms ) {
$alias =~ m/^\Q#$alias_local:\E/ or next;

my $aliases = $room->{aliases};
if( not defined $aliases ) {
next;
}
my $room_config = $rooms{$alias_local};

foreach my $alias ( @{$aliases} ) {
foreach my $alias_local ( keys %rooms ) {
$alias =~ m/^\Q#$alias_local:\E/ or next;
log_if_fail "Alias", $alias_local;
log_if_fail "Room", $room;

my $room_config = $rooms{$alias_local};
assert_eq( $canonical_alias, $alias, "Incorrect canonical_alias" );
assert_eq( $room->{num_joined_members}, 1, "Incorrect member count" );

log_if_fail "Alias", $alias_local;
log_if_fail "Room", $room;
if( defined $name ) {
assert_eq( $room_config->{name}, $name, 'room name' );
}
else {
defined $room_config->{name} and die "Expected not to find a name";
}

assert_eq( $canonical_alias, $alias, "Incorrect canonical_alias" );
assert_eq( $room->{num_joined_members}, 1, "Incorrect member count" );
if( defined $topic ) {
assert_eq( $room_config->{topic}, $topic, 'room topic' );
}
else {
defined $room_config->{topic} and die "Expected not to find a topic";
}

if( defined $name ) {
assert_eq( $room_config->{name}, $name, 'room name' );
$seen{$alias_local} = 1;
}
}
else {
defined $room_config->{name} and die "Expected not to find a name";
}

if( defined $topic ) {
assert_eq( $room_config->{topic}, $topic, 'room topic' );
}
else {
defined $room_config->{topic} and die "Expected not to find a topic";
}

$seen{$alias_local} = 1;
}
}
}

foreach my $key ( keys %seen ) {
$seen{$key} or die "Did not find a /publicRooms result for $key";
}
foreach my $key ( keys %seen ) {
$seen{$key} or die "Did not find a /publicRooms result for $key";
}

Future->done(1);
Future->done(1);
})
})
})
};

Expand Down