Skip to content

Commit

Permalink
Clean integration tests code
Browse files Browse the repository at this point in the history
  • Loading branch information
ufoscout committed Oct 9, 2017
1 parent a13cfc2 commit e6bb2e1
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions wait/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,7 @@ fn should_identify_the_open_port() {
let mut fun = || { count.inc(); };
assert_eq!(0, count.get());

thread::spawn(move || {
loop {
match tcpListener.accept() {
Ok(_) => { println!("Connection received!"); }
Err(_) => { println!("Error in received connection!"); }
}
}
});
listen_async(tcpListener);

thread::sleep(time::Duration::from_millis(250));
wait::wait(&sleeper, &new_config(&hosts, timeout, wait_before, wait_after ), &mut fun);
Expand All @@ -119,23 +112,8 @@ fn should_wait_multiple_hosts() {
let mut fun = || { count.inc(); };
assert_eq!(0, count.get());

thread::spawn(move || {
loop {
match tcpListener1.accept() {
Ok(_) => { println!("Connection received!"); }
Err(_) => { println!("Error in received connection!"); }
}
}
});

thread::spawn(move || {
loop {
match tcpListener2.accept() {
Ok(_) => { println!("Connection received!"); }
Err(_) => { println!("Error in received connection!"); }
}
}
});
listen_async(tcpListener1);
listen_async(tcpListener2);

thread::sleep(time::Duration::from_millis(250));
wait::wait(&sleeper, &new_config(&hosts, timeout, wait_before, wait_after ), &mut fun);
Expand All @@ -161,14 +139,7 @@ fn should_fail_if_not_all_hosts_are_available() {
let mut fun = || { count.inc(); };
assert_eq!(0, count.get());

thread::spawn(move || {
loop {
match tcpListener1.accept() {
Ok(_) => { println!("Connection received!"); }
Err(_) => { println!("Error in received connection!"); }
}
}
});
listen_async(tcpListener1);

thread::sleep(time::Duration::from_millis(250));
wait::wait(&sleeper, &new_config(&hosts, timeout, wait_before, wait_after ), &mut fun);
Expand Down Expand Up @@ -196,6 +167,17 @@ fn newTcpListener() -> TcpListener {
TcpListener::bind(socket).unwrap()
}

fn listen_async(listener: TcpListener) {
thread::spawn(move || {
loop {
match listener.accept() {
Ok(_) => { println!("Connection received!"); }
Err(_) => { println!("Error in received connection!"); }
}
}
});
}

fn free_port() -> u16 {
newTcpListener().local_addr().unwrap().port()
}
Expand Down

0 comments on commit e6bb2e1

Please sign in to comment.