-
Notifications
You must be signed in to change notification settings - Fork 56
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
}) | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 )], | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
}) | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And we definitely don't need four blank lines here. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 )], | ||
|
||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup. done.