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

Test for purge-by-ts #448

Merged
merged 1 commit into from
Jun 7, 2018
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
74 changes: 73 additions & 1 deletion tests/48admin.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use Future::Utils qw( repeat );

use Time::HiRes qw( time );

# poll the status endpoint until it completes. Returns the final status.
sub await_purge_complete {
Expand Down Expand Up @@ -145,6 +145,78 @@ sub await_purge_complete {
})
};

test "/purge_history by ts",
requires => [ local_admin_fixture(), local_user_and_room_fixtures() ],

do => sub {
my ( $admin, $user, $room_id ) = @_;

my ($last_event_id, $last_event_ts);

# we send 9 messages, get the current ts, and
# then send one more.
matrix_put_room_state( $user, $room_id,
type => "m.room.name",
content => { name => "A room name" },
)->then( sub {
matrix_sync( $user )
})->then( sub {
repeat( sub {
my $msgnum = $_[0];

matrix_send_room_text_message( $user, $room_id,
body => "Message $msgnum",
)
}, foreach => [ 1 .. 9 ])
})->then( sub {
$last_event_ts = time();
delay(0.01);
})->then( sub {
matrix_send_room_text_message( $user, $room_id,
body => "Message 10",
);
})->then( sub {
( $last_event_id ) = @_;
await_message_in_room( $user, $room_id, $last_event_id ),
})->then( sub {
do_request_json_for( $admin,
method => "POST",
uri => "/r0/admin/purge_history/$room_id",
content => {
purge_up_to_ts => int($last_event_ts * 1000),
},
)
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, "purge_id" );
my $purge_id = $body->{purge_id};
await_purge_complete( $admin, $purge_id );
})->then( sub {
my ( $purge_status ) = @_;
assert_eq( $purge_status, 'complete' );

# Test that /sync with an existing token still works.
matrix_sync_again( $user )
})->then( sub {
# Test that an initial /sync has the correct data.
matrix_sync( $user )
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body->{rooms}{join}, $room_id );
my $room = $body->{rooms}{join}{$room_id};

log_if_fail( "Room", $room->{timeline}{events} );

# The only message event should be the last one.
all {
$_->{type} ne "m.room.message" || $_->{event_id} eq $last_event_id
} @{ $room->{timeline}{events} } or die "Expected no message events";
Future->done( 1 );
})
};

test "Can backfill purged history",
requires => [ local_admin_fixture(), local_user_and_room_fixtures(),
remote_user_fixture(), qw( can_paginate_room_remotely ) ],
Expand Down