Skip to content

Commit

Permalink
Use TryFrom in tests using TimeSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
sirhcel committed Oct 20, 2024
1 parent 404aa68 commit 62a9227
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/sys/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! });
//!
//! let mut timer = Timer::new(clockid, sigevent).unwrap();
//! let expiration = Expiration::Interval(Duration::from_millis(250).into());
//! let expiration = Expiration::Interval(Duration::from_millis(250).try_into().unwrap());
//! let flags = TimerSetTimeFlags::empty();
//! timer.set(expiration, flags).expect("could not set timer");
//!
Expand Down
12 changes: 6 additions & 6 deletions test/sys/test_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn test_timestamping() {
} else {
sys_time - ts
};
assert!(std::time::Duration::from(diff).as_secs() < 60);
assert!(std::time::Duration::try_from(diff).unwrap().as_secs() < 60);
}

#[cfg(target_os = "freebsd")]
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn test_timestamping_realtime() {
} else {
sys_time - ts
};
assert!(std::time::Duration::from(diff).as_secs() < 60);
assert!(std::time::Duration::try_from(diff).unwrap().as_secs() < 60);
}

#[cfg(target_os = "freebsd")]
Expand Down Expand Up @@ -189,7 +189,7 @@ pub fn test_timestamping_monotonic() {
::nix::time::clock_gettime(::nix::time::ClockId::CLOCK_MONOTONIC)
.unwrap();
let diff = sys_time - ts; // Monotonic clock sys_time must be greater
assert!(std::time::Duration::from(diff).as_secs() < 60);
assert!(std::time::Duration::try_from(diff).unwrap().as_secs() < 60);
}

#[test]
Expand Down Expand Up @@ -2985,7 +2985,7 @@ pub fn test_txtime() {
let iov1 = [std::io::IoSlice::new(&sbuf)];

let now = clock_gettime(ClockId::CLOCK_MONOTONIC).unwrap();
let delay = std::time::Duration::from_secs(1).into();
let delay = std::time::Duration::from_secs(1).try_into().unwrap();
let txtime = (now + delay).num_nanoseconds() as u64;

let cmsg = ControlMessage::TxTime(&txtime);
Expand Down Expand Up @@ -3099,7 +3099,7 @@ fn test_recvmm2() -> nix::Result<()> {

let mut data = MultiHeaders::<()>::preallocate(recv_iovs.len(), Some(cmsg));

let t = TimeSpec::from_duration(std::time::Duration::from_secs(10));
let t = TimeSpec::try_from_duration(std::time::Duration::from_secs(10)).unwrap();

let recv = recvmmsg(
rsock.as_raw_fd(),
Expand All @@ -3125,7 +3125,7 @@ fn test_recvmm2() -> nix::Result<()> {
} else {
sys_time - ts
};
assert!(std::time::Duration::from(diff).as_secs() < 60);
assert!(std::time::Duration::try_from(diff).unwrap().as_secs() < 60);
#[cfg(not(any(qemu, target_arch = "aarch64")))]
{
saw_time = true;
Expand Down
2 changes: 1 addition & 1 deletion test/sys/test_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn alarm_fires() {
});
let mut timer =
Timer::new(clockid, sigevent).expect("failed to create timer");
let expiration = Expiration::Interval(TIMER_PERIOD.into());
let expiration = Expiration::Interval(TIMER_PERIOD.try_into().unwrap());
let flags = TimerSetTimeFlags::empty();
timer.set(expiration, flags).expect("could not set timer");

Expand Down

0 comments on commit 62a9227

Please sign in to comment.