@@ -183,6 +183,43 @@ mod datastore_tests {
183183 assert_eq ! ( event_count, 2 ) ;
184184 }
185185
186+ /// Tests that events that cover a timeperiod get included when that timeperiod is queried.
187+ #[ test]
188+ fn test_get_events_filters_cover ( ) {
189+ // TODO: Also test event-cutoff, although perhaps that happens in the transforms/queries?
190+
191+ // Setup datastore
192+ let ds = Datastore :: new_in_memory ( false ) ;
193+ let bucket = create_test_bucket ( & ds) ;
194+
195+ let now = Utc :: now ( ) ;
196+
197+ // Insert event
198+ let e1 = Event {
199+ id : None ,
200+ timestamp : Utc :: now ( ) ,
201+ duration : Duration :: seconds ( 100 ) ,
202+ data : json_map ! { "key" : json!( "value" ) } ,
203+ } ;
204+
205+ let event_list = [ e1. clone ( ) ] ;
206+ ds. insert_events ( & bucket. id , & event_list) . unwrap ( ) ;
207+
208+ info ! ( "Get event that covers queried timeperiod" ) ;
209+ let query_start = now + Duration :: seconds ( 1 ) ;
210+ let query_end = query_start + Duration :: seconds ( 1 ) ;
211+ let fetched_events_limit = ds
212+ . get_events ( & bucket. id , Some ( query_start) , Some ( query_end) , Some ( 1 ) )
213+ . unwrap ( ) ;
214+ assert_eq ! ( fetched_events_limit. len( ) , 1 ) ;
215+
216+ // Get eventcount
217+ let event_count = ds
218+ . get_event_count ( & bucket. id , Some ( query_start) , Some ( query_end) )
219+ . unwrap ( ) ;
220+ assert_eq ! ( event_count, 1 ) ;
221+ }
222+
186223 #[ test]
187224 fn test_events_delete ( ) {
188225 // Setup datastore
0 commit comments