-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix notify-debouncer-full by removing mock_instant crate
Trying to use mock_instant across multiple crates was a bad idea. All functions requiring a clock were removed from the notify-types crate and custom time mocking functions were added.
- Loading branch information
Showing
7 changed files
with
72 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#[cfg(not(test))] | ||
mod build { | ||
use std::time::Instant; | ||
|
||
pub fn now() -> Instant { | ||
Instant::now() | ||
} | ||
} | ||
|
||
#[cfg(not(test))] | ||
pub use build::*; | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::{ | ||
sync::Mutex, | ||
time::{Duration, Instant}, | ||
}; | ||
|
||
thread_local! { | ||
static NOW: Mutex<Option<Instant>> = Mutex::new(None); | ||
} | ||
|
||
pub fn now() -> Instant { | ||
let time = NOW.with(|now| *now.lock().unwrap()); | ||
time.unwrap_or_else(|| Instant::now()) | ||
} | ||
|
||
pub struct MockTime; | ||
|
||
impl MockTime { | ||
pub fn set_time(time: Instant) { | ||
NOW.with(|now| *now.lock().unwrap() = Some(time)); | ||
} | ||
|
||
pub fn advance(delta: Duration) { | ||
NOW.with(|now| { | ||
if let Some(n) = &mut *now.lock().unwrap() { | ||
*n += delta; | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
pub use test::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters