Skip to content

Commit

Permalink
Merge pull request #204 from tkrs/avoid-zero-duration-error
Browse files Browse the repository at this point in the history
test: fix to avoid zero duration error
  • Loading branch information
tkrs authored Dec 17, 2024
2 parents fb32511 + b0ebaf4 commit 135b489
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ impl Connect<TcpStream> for TcpStream {
{
TcpStream::connect(addr).map(|s| {
s.set_nodelay(true).unwrap();
s.set_read_timeout(Some(settings.read_timeout)).unwrap();
s.set_write_timeout(Some(settings.write_timeout)).unwrap();
if !settings.read_timeout.is_zero() {
s.set_read_timeout(Some(settings.read_timeout)).unwrap();
}
if !settings.write_timeout.is_zero() {
s.set_write_timeout(Some(settings.write_timeout)).unwrap();
}
s
})
}
Expand Down
5 changes: 3 additions & 2 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::net::{TcpStream, ToSocketAddrs};
use std::thread;
use std::time::{Duration, Instant, SystemTime};

#[derive(Debug)]
pub struct Worker {
handler: Option<thread::JoinHandle<()>>,
}
Expand Down Expand Up @@ -121,7 +122,7 @@ mod tests {

#[test]
fn worker_create_should_return_err_when_the_connection_open_is_failed() {
let addr = "127.0.0.1:25";
let addr = "127.0.0.1:9";
let settings = ConnectionSettings {
connect_retry_initial_delay: Duration::new(0, 1),
connect_retry_max_delay: Duration::new(0, 1),
Expand All @@ -130,7 +131,7 @@ mod tests {
};
let (_, receiver) = unbounded();
let ret = Worker::create(addr, settings, receiver, Duration::from_millis(1), 1);
assert!(ret.is_err())
assert!(ret.is_err(), "got: {:?}", ret)
}

struct Q;
Expand Down

0 comments on commit 135b489

Please sign in to comment.