Skip to content

Commit d6a61d9

Browse files
authored
test: adding explicit test for long pulse merge (#307)
this the exact scenario which is used on the new swift-based macos window watcher
1 parent 7c2b31f commit d6a61d9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

aw-transform/src/heartbeat.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ mod tests {
9494
// TODO: needs more tests!
9595
}
9696

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+
97125
#[test]
98126
fn test_heartbeat_data() {
99127
let now = Utc::now();

0 commit comments

Comments
 (0)