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

Integration tests for full_state incremental sync #32

Merged
merged 3 commits into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions tests/31sync/03joined.pl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@
my $room = $body->{rooms}{joined}{$room_id};
(!defined $room) or die "Unchanged rooms shouldn't be in the sync response";

# do another sync, with full_state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test intended to check interaction with the previous sync above? If not, then perhaps it would be best in its own test, for independence.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. done.

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)
})
};
Expand Down
54 changes: 54 additions & 0 deletions tests/31sync/04timeline.pl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,60 @@
};


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);
})
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure we don't need three blank lines here :)



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

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


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);
})
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we definitely don't need four blank lines here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

five, actually.

I'm not sure I share your fear of whitespace, but which ones do you think need removing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the four blank lines between this test and the next; lines 273 to 276. Usually one is the style, though some people are using two blank lines to separate toplevel functions - I don't mind that. Four just seems a bit excessive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! yes it does. two seems like a good amount - it distinguishes the gap between tests from blocks within tests.




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