Skip to content

Commit

Permalink
Test for purge-by-ts
Browse files Browse the repository at this point in the history
(which is fixed by matrix-org/synapse#3363)
  • Loading branch information
richvdh committed Jun 6, 2018
1 parent 775fae9 commit 26969ef
Showing 1 changed file with 73 additions and 1 deletion.
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

0 comments on commit 26969ef

Please sign in to comment.