mirror of
https://github.com/telemt/telemt.git
synced 2026-09-25 12:05:58 +03:00
Update activity.rs
Co-Authored-By: brekotis <93345790+brekotis@users.noreply.github.com>
This commit is contained in:
+29
-29
@@ -42,35 +42,6 @@ impl WebSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn progress_does_not_extend_the_authenticated_peer_lease() {
|
|
||||||
let started = Instant::now();
|
|
||||||
let mut activity = SessionActivity::new(started);
|
|
||||||
activity.touch_progress(started + Duration::from_secs(4));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
activity.peer_idle(started + Duration::from_secs(9)),
|
|
||||||
Duration::from_secs(9)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
activity.progress_idle(started + Duration::from_secs(9)),
|
|
||||||
Duration::from_secs(5)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
activity.touch_peer(started + Duration::from_secs(9)),
|
|
||||||
Duration::from_secs(9)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
activity.peer_idle(started + Duration::from_secs(10)),
|
|
||||||
Duration::from_secs(1)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SessionActivity {
|
impl SessionActivity {
|
||||||
/// Starts both activity clocks at the same session creation instant.
|
/// Starts both activity clocks at the same session creation instant.
|
||||||
pub(super) fn new(now: Instant) -> Self {
|
pub(super) fn new(now: Instant) -> Self {
|
||||||
@@ -103,3 +74,32 @@ impl SessionActivity {
|
|||||||
now.saturating_duration_since(self.last_progress)
|
now.saturating_duration_since(self.last_progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn progress_does_not_extend_the_authenticated_peer_lease() {
|
||||||
|
let started = Instant::now();
|
||||||
|
let mut activity = SessionActivity::new(started);
|
||||||
|
activity.touch_progress(started + Duration::from_secs(4));
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
activity.peer_idle(started + Duration::from_secs(9)),
|
||||||
|
Duration::from_secs(9)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
activity.progress_idle(started + Duration::from_secs(9)),
|
||||||
|
Duration::from_secs(5)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
activity.touch_peer(started + Duration::from_secs(9)),
|
||||||
|
Duration::from_secs(9)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
activity.peer_idle(started + Duration::from_secs(10)),
|
||||||
|
Duration::from_secs(1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user