Skip to content

Assert Timings #356

Answered by asomers
StefanSchoof asked this question in Questions
Feb 2, 2022 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

The timing won't be precise, but you should be able to do it by inserting sleeps into the returner. Like this:

let mut mock = MockMyThing::default();
mock.expect_go_high()
    .returning(|| {
        std::thread::sleep(std::time::Duration::from_millis(10));
        Ok(())
    })

Or are you saying you want to assert that the code under test slept for a certain amount of time? If so, you could try something like this:

let mut high_time = None;
let mut low_time = None;
let mut mock = MockMyThing();
mock.expect_go_high()
    .returning(|| {
        high_time = Some(std::time::Instant::now());
        Ok(())
    });
mock.expect_go_low()
    .returning(|| {
        low_time = Some(std::time::In…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@StefanSchoof
Comment options

@StefanSchoof
Comment options

@asomers
Comment options

Answer selected by StefanSchoof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants