Skip to content

Commit d630718

Browse files
committed
Use TryFrom in tests using TimeSpec
1 parent 404aa68 commit d630718

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/sys/timer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//! });
3939
//!
4040
//! let mut timer = Timer::new(clockid, sigevent).unwrap();
41-
//! let expiration = Expiration::Interval(Duration::from_millis(250).into());
41+
//! let expiration = Expiration::Interval(Duration::from_millis(250).try_into().unwrap());
4242
//! let flags = TimerSetTimeFlags::empty();
4343
//! timer.set(expiration, flags).expect("could not set timer");
4444
//!

test/sys/test_socket.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn test_timestamping() {
6969
} else {
7070
sys_time - ts
7171
};
72-
assert!(std::time::Duration::from(diff).as_secs() < 60);
72+
assert!(std::time::Duration::try_from(diff).unwrap().as_secs() < 60);
7373
}
7474

7575
#[cfg(target_os = "freebsd")]
@@ -131,7 +131,7 @@ pub fn test_timestamping_realtime() {
131131
} else {
132132
sys_time - ts
133133
};
134-
assert!(std::time::Duration::from(diff).as_secs() < 60);
134+
assert!(std::time::Duration::try_from(diff).unwrap().as_secs() < 60);
135135
}
136136

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

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

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

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

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

3102-
let t = TimeSpec::from_duration(std::time::Duration::from_secs(10));
3102+
let t = TimeSpec::try_from_duration(std::time::Duration::from_secs(10))
3103+
.unwrap();
31033104

31043105
let recv = recvmmsg(
31053106
rsock.as_raw_fd(),
@@ -3125,7 +3126,9 @@ fn test_recvmm2() -> nix::Result<()> {
31253126
} else {
31263127
sys_time - ts
31273128
};
3128-
assert!(std::time::Duration::from(diff).as_secs() < 60);
3129+
assert!(
3130+
std::time::Duration::try_from(diff).unwrap().as_secs() < 60
3131+
);
31293132
#[cfg(not(any(qemu, target_arch = "aarch64")))]
31303133
{
31313134
saw_time = true;

test/sys/test_timer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn alarm_fires() {
5050
});
5151
let mut timer =
5252
Timer::new(clockid, sigevent).expect("failed to create timer");
53-
let expiration = Expiration::Interval(TIMER_PERIOD.into());
53+
let expiration = Expiration::Interval(TIMER_PERIOD.try_into().unwrap());
5454
let flags = TimerSetTimeFlags::empty();
5555
timer.set(expiration, flags).expect("could not set timer");
5656

0 commit comments

Comments
 (0)