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 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
57 changes: 39 additions & 18 deletions tests/48admin.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,51 @@ 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 ) = @_;

assert_json_keys( $body, qw( devices user_id ) );
assert_eq( $body->{user_id}, $user->user_id, "user_id" );
assert_json_object( $body->{devices} );
# 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).
repeat_until_true sub {
do_request_json_for( $user,
method => "GET",
uri => "/v3/admin/whois/".$user->user_id,
)->then( sub {
my ( $body ) = @_;

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 ) );
}
assert_json_keys( $body, qw( devices user_id ) );
assert_eq( $body->{user_id}, $user->user_id, "user_id" );
assert_json_object( $body->{devices} );

# Whether we've found a connection with the right keys
# (ip, last_seen, user_agent).
my $found_connections = 0;

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} );
# The `connections` may not yet be populated. If there *is* a connection,
# we check that it has the right shape. If `connections` is still empty, we
# tell `repeat_until_true` to retry by returning a falsey value.
foreach my $connection ( @{ $value->{sessions}[0]{connections} } ) {
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
assert_json_keys(
$connection,
qw( ip last_seen user_agent )
);

$found_connections = 1;
}
}

Future->done( 1 );
Future->done( $found_connections );
});
}, initial_delay => 0.5;
});
};

Expand Down