I am writing an integration test where I spawn two processes, a tcp listener and a sender. I am using TcpStream to send a message to the TcpListener. It doesn't work because both processes are trying to use the same port.
How do I solve this problem?
thread 'main' panicked at 'called
Result::unwrap()
on anErr
value: Os { code: 98, kind: AddrInUse, message: "Address already in use" }', libcore/result.rs:945:5
note: Run withRUST_BACKTRACE=1
for a backtrace.
test code
#[test]
fn say_hello() {
let mut listener = Command::new("./target/debug/teleport")
.arg("8080")
.arg("listen")
.stdout(Stdio::piped())
.spawn()
.expect("failed to execute child");let mut sender = Command::new("./target/debug/teleport") .arg("8080") .arg("send") .spawn() .expect("failed to execute child"); let mut s = String::new(); match listener.stdout.unwrap().read_to_string(&mut s) { Err(why) => panic!("couldn't read wc stdout: {}", why.description()), Ok(_) => print!("wc responded with:\n{}", s), } assert_eq!(s, "Goodbye")
}