diff options
| author | David Lönnhager <david.l@mullvad.net> | 2024-04-19 09:53:54 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-04-23 15:33:28 +0200 |
| commit | 0ba9f4c59118239b900cd52355e817bbe1f1eaed (patch) | |
| tree | 8960d3409d17ae8f2845122ff0ee41525fd356ff | |
| parent | 87317c21da567fb44292828c51e4b3a6607e6801 (diff) | |
| download | mullvadvpn-0ba9f4c59118239b900cd52355e817bbe1f1eaed.tar.xz mullvadvpn-0ba9f4c59118239b900cd52355e817bbe1f1eaed.zip | |
Make talpid-time timers mockable in tests
| -rw-r--r-- | talpid-time/Cargo.toml | 3 | ||||
| -rw-r--r-- | talpid-time/src/lib.rs | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/talpid-time/Cargo.toml b/talpid-time/Cargo.toml index 40fd2f5e74..4f6158ee53 100644 --- a/talpid-time/Cargo.toml +++ b/talpid-time/Cargo.toml @@ -10,6 +10,9 @@ rust-version.workspace = true [lints] workspace = true +[features] +test = [] + [dependencies] tokio = { workspace = true, features = ["time"] } libc = "0.2" diff --git a/talpid-time/src/lib.rs b/talpid-time/src/lib.rs index 3b536eda54..4ca9c8bf5d 100644 --- a/talpid-time/src/lib.rs +++ b/talpid-time/src/lib.rs @@ -1,14 +1,20 @@ use std::time::Duration; -#[cfg(target_os = "windows")] +#[cfg(all(not(feature = "test"), target_os = "windows"))] mod inner { pub use std::time::Instant; } -#[cfg(unix)] +#[cfg(all(not(feature = "test"), unix))] #[path = "unix.rs"] mod inner; +#[cfg(feature = "test")] +mod inner { + /// Use mockable time for tests + pub use tokio::time::Instant; +} + const MAX_SLEEP_INTERVAL: Duration = Duration::from_secs(60); /// Represents a measurement of a monotonic clock. |
