@@ -739,7 +739,7 @@ mod tests {
739
739
740
740
#[ test]
741
741
fn test_frozen_sliding_sync_room_serialization ( ) {
742
- let frozen_sliding_sync_room = FrozenSlidingSyncRoom {
742
+ let frozen_room = FrozenSlidingSyncRoom {
743
743
room_id : room_id ! ( "!29fhd83h92h0:example.com" ) . to_owned ( ) ,
744
744
inner : v4:: SlidingSyncRoom :: default ( ) ,
745
745
timeline_queue : vector ! [ TimelineEvent :: new(
@@ -758,7 +758,7 @@ mod tests {
758
758
} ;
759
759
760
760
assert_eq ! (
761
- serde_json:: to_value( & frozen_sliding_sync_room ) . unwrap( ) ,
761
+ serde_json:: to_value( & frozen_room ) . unwrap( ) ,
762
762
json!( {
763
763
"room_id" : "!29fhd83h92h0:example.com" ,
764
764
"inner" : { } ,
@@ -781,4 +781,86 @@ mod tests {
781
781
} )
782
782
) ;
783
783
}
784
+
785
+ #[ tokio:: test]
786
+ async fn test_frozen_sliding_sync_room_has_a_capped_version_of_the_timeline ( ) {
787
+ // Just below the limit.
788
+ {
789
+ let max = NUMBER_OF_TIMELINE_EVENTS_TO_KEEP_FOR_THE_CACHE - 1 ;
790
+ let timeline_events = ( 0 ..=max)
791
+ . map ( |nth| {
792
+ TimelineEvent :: new (
793
+ Raw :: new ( & json ! ( {
794
+ "content" : RoomMessageEventContent :: text_plain( format!( "message {nth}" ) ) ,
795
+ "type" : "m.room.message" ,
796
+ "event_id" : format!( "$x{nth}:baz.org" ) ,
797
+ "room_id" : "!foo:bar.org" ,
798
+ "origin_server_ts" : nth,
799
+ "sender" : "@alice:baz.org" ,
800
+ } ) )
801
+ . unwrap ( )
802
+ . cast ( ) ,
803
+ )
804
+ . into ( )
805
+ } )
806
+ . collect :: < Vec < _ > > ( ) ;
807
+
808
+ let room = new_room_with_timeline (
809
+ room_id ! ( "!foo:bar.org" ) ,
810
+ room_response ! ( { } ) ,
811
+ timeline_events,
812
+ )
813
+ . await ;
814
+
815
+ let frozen_room = FrozenSlidingSyncRoom :: from ( & room) ;
816
+ assert_eq ! ( frozen_room. timeline_queue. len( ) , max + 1 ) ;
817
+ // Check that the last event is the last event of the timeline, i.e. we only
818
+ // keep the _latest_ events, not the _first_ events.
819
+ assert_eq ! (
820
+ frozen_room. timeline_queue. last( ) . unwrap( ) . event. deserialize( ) . unwrap( ) . event_id( ) ,
821
+ & format!( "$x{max}:baz.org" )
822
+ ) ;
823
+ }
824
+
825
+ // Above the limit.
826
+ {
827
+ let max = NUMBER_OF_TIMELINE_EVENTS_TO_KEEP_FOR_THE_CACHE + 2 ;
828
+ let timeline_events = ( 0 ..=max)
829
+ . map ( |nth| {
830
+ TimelineEvent :: new (
831
+ Raw :: new ( & json ! ( {
832
+ "content" : RoomMessageEventContent :: text_plain( format!( "message {nth}" ) ) ,
833
+ "type" : "m.room.message" ,
834
+ "event_id" : format!( "$x{nth}:baz.org" ) ,
835
+ "room_id" : "!foo:bar.org" ,
836
+ "origin_server_ts" : nth,
837
+ "sender" : "@alice:baz.org" ,
838
+ } ) )
839
+ . unwrap ( )
840
+ . cast ( ) ,
841
+ )
842
+ . into ( )
843
+ } )
844
+ . collect :: < Vec < _ > > ( ) ;
845
+
846
+ let room = new_room_with_timeline (
847
+ room_id ! ( "!foo:bar.org" ) ,
848
+ room_response ! ( { } ) ,
849
+ timeline_events,
850
+ )
851
+ . await ;
852
+
853
+ let frozen_room = FrozenSlidingSyncRoom :: from ( & room) ;
854
+ assert_eq ! (
855
+ frozen_room. timeline_queue. len( ) ,
856
+ NUMBER_OF_TIMELINE_EVENTS_TO_KEEP_FOR_THE_CACHE
857
+ ) ;
858
+ // Check that the last event is the last event of the timeline, i.e. we only
859
+ // keep the _latest_ events, not the _first_ events.
860
+ assert_eq ! (
861
+ frozen_room. timeline_queue. last( ) . unwrap( ) . event. deserialize( ) . unwrap( ) . event_id( ) ,
862
+ & format!( "$x{max}:baz.org" )
863
+ ) ;
864
+ }
865
+ }
784
866
}
0 commit comments