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

Retry /whois to allow for propagation/persistence delay #1222

Merged
merged 7 commits into from
Apr 1, 2022
Merged
Changes from 3 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
53 changes: 36 additions & 17 deletions tests/48admin.pl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ sub await_purge_complete {
test "/whois",
requires => [ $main::API_CLIENTS[0] ],

timeout => 10,

reivilibre marked this conversation as resolved.
Show resolved Hide resolved
do => sub {
my ( $http ) = @_;

Expand All @@ -40,30 +42,47 @@ sub await_purge_complete {
# tightly control the actions taken by that user.
# Conceivably this API may change based on the number of API calls the
# user made, for instance.

matrix_register_user( $http, "admin" )
->then( sub {
( $user ) = @_;

do_request_json_for( $user,
method => "GET",
uri => "/v3/admin/whois/".$user->user_id,
)
})->then( sub {
my ( $body ) = @_;
# Synapse flushes IP addresses to the database every 5 seconds, so we
# need to keep checking because the IP address won't appear for a few
# seconds (unless the worker that flushes the IP addresses is the same
# as the one that handles /whois).
return retry_until_success sub {
return do_request_json_for( $user,
method => "GET",
uri => "/v3/admin/whois/".$user->user_id,
)->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( devices user_id ) );
assert_eq( $body->{user_id}, $user->user_id, "user_id" );
assert_json_object( $body->{devices} );
assert_json_keys( $body, qw( devices user_id ) );
assert_eq( $body->{user_id}, $user->user_id, "user_id" );
assert_json_object( $body->{devices} );

foreach my $value ( values %{ $body->{devices} } ) {
assert_json_keys( $value, "sessions" );
assert_json_list( $value->{sessions} );
assert_json_keys( $value->{sessions}[0], "connections" );
assert_json_list( $value->{sessions}[0]{connections} );
assert_json_keys( $value->{sessions}[0]{connections}[0], qw( ip last_seen user_agent ) );
}
foreach my $value ( values %{ $body->{devices} } ) {
assert_json_keys( $value, "sessions" );
assert_json_list( $value->{sessions} );
assert_json_keys( $value->{sessions}[0], "connections" );
assert_json_list( $value->{sessions}[0]{connections} );
assert_json_object( $value->{sessions}[0]{connections}[0] );
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
}

Future->done( 1 );
Future->done( $body->{devices} );
});
}, initial_delay => 0.5,
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
check => sub {
# Once the connections object is ready, check that it contains
# the right keys.
foreach my $value ( values %{ $_[0] } ) {
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
assert_json_keys(
$value->{sessions}[0]{connections}[0],
qw( ip last_seen user_agent )
);
}
};
});
};

Expand Down