File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,34 @@ mod tests {
94
94
// TODO: needs more tests!
95
95
}
96
96
97
+ #[ test]
98
+ fn test_heartbeat_long_pulse_merge ( ) {
99
+ let now = Utc :: now ( ) ;
100
+ let event = Event {
101
+ id : None ,
102
+ timestamp : now,
103
+ duration : Duration :: seconds ( 1 ) ,
104
+ data : json_map ! { "test" : json!( 1 ) } ,
105
+ } ;
106
+ let long_pulse_event = Event {
107
+ id : None ,
108
+ // note that no duration is sent, which is how aw-client works
109
+ duration : Duration :: seconds ( 0 ) ,
110
+ timestamp : now + Duration :: seconds ( 120 ) ,
111
+ data : json_map ! { "test" : json!( 1 ) } ,
112
+ } ;
113
+
114
+ // Merge result
115
+ let res_merge = heartbeat ( & event, & long_pulse_event, 120.0 ) . unwrap ( ) ;
116
+ assert_eq ! ( res_merge. timestamp, now) ;
117
+ assert_eq ! ( res_merge. data, event. data) ;
118
+ assert_eq ! ( res_merge. duration, Duration :: seconds( 120 ) ) ;
119
+
120
+ // No merge result when pulsetime is less than the timestamp delta between heartbeats
121
+ let res_no_merge = heartbeat ( & event, & long_pulse_event, 60.0 ) ;
122
+ assert ! ( res_no_merge. is_none( ) ) ;
123
+ }
124
+
97
125
#[ test]
98
126
fn test_heartbeat_data ( ) {
99
127
let now = Utc :: now ( ) ;
You can’t perform that action at this time.
0 commit comments