Skip to content

Commit

Permalink
Merge pull request #32 from matrix-org/rav/full_state_sync
Browse files Browse the repository at this point in the history
Integration tests for full_state incremental sync
  • Loading branch information
richvdh committed Oct 28, 2015
2 parents 5d437bc + f7edd93 commit fbf71bc
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/31sync/03joined.pl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,46 @@
};


test "Full state sync includes joined rooms",
requires => [qw( first_api_client can_sync )],

check => sub {
my ( $http ) = @_;

my ( $user, $filter_id, $room_id );

my $filter = { room => { timeline => { limit => 10 } } };

matrix_register_user_with_filter( $http, $filter )->then( sub {
( $user, $filter ) = @_;

matrix_create_room( $user )
})->then( sub {
( $room_id ) = @_;

matrix_sync( $user, filter => $filter_id )
})->then( sub {
my ( $body ) = @_;

matrix_sync( $user, filter => $filter_id, since => $body->{next_batch},
full_state => 'true');
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{joined}{$room_id};

require_json_keys( $room, qw( event_map timeline state ephemeral ));
require_json_keys( $room->{timeline}, qw( events limited prev_batch ));
require_json_keys( $room->{state}, qw( events ));
require_json_keys( $room->{ephemeral}, qw( events ));
require_json_keys( $room->{event_map}, @{ $room->{timeline}{events} } );
require_json_keys( $room->{event_map}, @{ $room->{state}{events} } );

Future->done(1)
})
};


test "Newly joined room is included in an incremental sync",
requires => [qw( first_api_client can_sync )],

Expand Down
53 changes: 53 additions & 0 deletions tests/31sync/04timeline.pl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,59 @@
};


test "A full_state incremental update returns only recent timeline",
requires => [qw( first_api_client can_sync )],

check => sub {
my ( $http ) = @_;

my ( $user, $filter_id, $room_id, $next_batch );

my $filter = { room => { timeline => { limit => 1 } } };

matrix_register_user_with_filter( $http, $filter )->then( sub {
( $user, $filter_id ) = @_;

matrix_create_room( $user );
})->then( sub {
( $room_id ) = @_;

matrix_sync( $user, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;

$next_batch = $body->{next_batch};
Future->needs_all( map {
matrix_send_room_message( $user, $room_id,
content => { "filler" => $_ },
type => "a.made.up.filler.type",
)
} 0 .. 10 );
})->then( sub {
matrix_send_room_message( $user, $room_id,
content => { "filler" => $_ },
type => "another.filler.type",
);
})->then( sub {
matrix_sync( $user, filter => $filter_id, since => $next_batch,
full_state => 'true');
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{joined}{$room_id};
require_json_keys( $room, qw( event_map timeline state ephemeral ));

@{ $room->{timeline}{events} } == 1
or die "Expected only one timeline event";
my $event_id = $room->{timeline}{events}[0];
$room->{event_map}{$event_id}{type} eq "another.filler.type"
or die "Unexpected timeline event type";

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


test "A prev_batch token can be used in the v1 messages API",
requires => [qw( first_api_client can_sync )],

Expand Down
81 changes: 81 additions & 0 deletions tests/31sync/06state.pl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,87 @@
};


test "A full_state incremental update returns all state",
requires => [qw( first_api_client can_sync )],

check => sub {
my ( $http ) = @_;

my ( $user, $filter_id, $room_id, $next_batch );

my $filter = { room => {
timeline => { limit => 1 },
state => { types => [ "a.madeup.test.state" ] },
} };

matrix_register_user_with_filter( $http, $filter )->then( sub {
( $user, $filter_id ) = @_;

matrix_create_room( $user );
})->then( sub {
( $room_id ) = @_;

matrix_put_room_state( $user, $room_id,
type => "a.madeup.test.state",
content => { "my_key" => 1 },
state_key => "this_state_changes"
);
})->then( sub {
matrix_put_room_state( $user, $room_id,
type => "a.madeup.test.state",
content => { "my_key" => 1 },
state_key => "this_state_does_not_change"
);
})->then( sub {
matrix_sync( $user, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;

$next_batch = $body->{next_batch};
@{ $body->{rooms}{joined}{$room_id}{state}{events} } == 2
or die "Expected two state events";

matrix_put_room_state( $user, $room_id,
type => "a.madeup.test.state",
content => { "my_key" => 2 },
state_key => "this_state_changes",
);
})->then( sub {
Future->needs_all( map {
matrix_send_room_message( $user, $room_id,
content => { "filler" => $_ },
type => "a.made.up.filler.type",
)
} 0 .. 10 );
})->then( sub {
matrix_sync( $user, filter => $filter_id, since => $next_batch,
full_state => 'true');
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{joined}{$room_id};
require_json_keys( $room, qw( event_map timeline state ephemeral ));

@{ $room->{state}{events} } == 2
or die "Expected only two state events";

my $event_id = $room->{state}{events}[1];
my $event = $room->{event_map}{$event_id};
$event->{type} eq "a.madeup.test.state"
or die "Unexpected state event type";
$event->{state_key} eq 'this_state_changes'
or die "Unexpected event state_key";
$event->{content}{my_key} == 2
or die "Unexpected event content";

@{ $room->{timeline}{events} } == 1
or die "Expected only one timeline event";

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


test "When user joins a room the state is included in the next sync",
requires => [qw( first_api_client can_sync )],

Expand Down
36 changes: 36 additions & 0 deletions tests/31sync/09archived.pl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,42 @@
};


test "Left rooms appear in the archived section of full state sync",
requires => [qw( first_api_client can_sync )],

check => sub {
my ( $http ) = @_;

my ( $user, $filter_id, $room_id, $next );

matrix_register_user_with_filter( $http, {} )->then( sub {
( $user, $filter_id ) = @_;

matrix_create_room( $user );
})->then( sub {
( $room_id ) = @_;

matrix_sync( $user, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;

$next = $body->{next_batch};

matrix_leave_room( $user, $room_id );
})->then( sub {
matrix_sync( $user, filter => $filter_id,
since => $next, full_state => 'true');
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{archived}{$room_id};
require_json_keys( $room, qw( event_map timeline state ));

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


test "Archived rooms only contain history from before the user left",
requires => [qw( first_api_client can_sync )],

Expand Down

0 comments on commit fbf71bc

Please sign in to comment.