pub struct TestClock { /* private fields */ }Expand description
Hand-stepped clock for deterministic tests. advance(d) moves
time forward by d; the scheduler then catches up via poll().
Implementations§
Source§impl TestClock
impl TestClock
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/sample_app.rs (line 216)
209fn deadline_session_idle() {
210 use std::time::Duration;
211 use subms_timer_wheel::{DeadlineScheduler, TestClock};
212 println!("\n== deadline-scheduler: FIX session idle timeout ==");
213
214 let idle = Duration::from_millis(30);
215 let mut sched: DeadlineScheduler<&'static str, TestClock> =
216 DeadlineScheduler::new(256, TestClock::new(), Duration::from_millis(1));
217
218 let session = sched.schedule_after(idle, "SESSION-1");
219 let mut elapsed = 0u64;
220 for gap in [10u64, 15] {
221 sched.clock().advance(Duration::from_millis(gap));
222 elapsed += gap;
223 assert!(sched.poll().is_empty(), "traffic keeps the session alive");
224 sched.reschedule_after(session, idle);
225 println!(
226 " inbound msg at +{elapsed}ms, idle deadline now +{}ms",
227 elapsed + 30
228 );
229 }
230 // Then the counterparty goes quiet.
231 sched.clock().advance(Duration::from_millis(30));
232 let dead = sched.poll();
233 println!(" no traffic for {}ms -> {:?}", idle.as_millis(), dead);
234 assert_eq!(dead, vec!["SESSION-1"], "the idle timeout fires");
235}Sourcepub fn advance(&self, d: Duration)
pub fn advance(&self, d: Duration)
Examples found in repository?
examples/sample_app.rs (line 221)
209fn deadline_session_idle() {
210 use std::time::Duration;
211 use subms_timer_wheel::{DeadlineScheduler, TestClock};
212 println!("\n== deadline-scheduler: FIX session idle timeout ==");
213
214 let idle = Duration::from_millis(30);
215 let mut sched: DeadlineScheduler<&'static str, TestClock> =
216 DeadlineScheduler::new(256, TestClock::new(), Duration::from_millis(1));
217
218 let session = sched.schedule_after(idle, "SESSION-1");
219 let mut elapsed = 0u64;
220 for gap in [10u64, 15] {
221 sched.clock().advance(Duration::from_millis(gap));
222 elapsed += gap;
223 assert!(sched.poll().is_empty(), "traffic keeps the session alive");
224 sched.reschedule_after(session, idle);
225 println!(
226 " inbound msg at +{elapsed}ms, idle deadline now +{}ms",
227 elapsed + 30
228 );
229 }
230 // Then the counterparty goes quiet.
231 sched.clock().advance(Duration::from_millis(30));
232 let dead = sched.poll();
233 println!(" no traffic for {}ms -> {:?}", idle.as_millis(), dead);
234 assert_eq!(dead, vec!["SESSION-1"], "the idle timeout fires");
235}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TestClock
impl !RefUnwindSafe for TestClock
impl !Sync for TestClock
impl Send for TestClock
impl Unpin for TestClock
impl UnsafeUnpin for TestClock
impl UnwindSafe for TestClock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more