diff --git a/src/libcore/rt/test.rs b/src/libcore/rt/test.rs index dfc058d6eba5..585d43a3ade8 100644 --- a/src/libcore/rt/test.rs +++ b/src/libcore/rt/test.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use super::io::net::ip::{IpAddr, Ipv4}; + // For setting up tests of the new scheduler pub fn run_in_newsched_task(f: ~fn()) { use cell::Cell; @@ -53,3 +55,8 @@ pub fn next_test_port() -> u16 { fn rust_dbg_next_port() -> ::libc::uintptr_t; } } + +/// Get a unique localhost:port pair starting at 9600 +pub fn next_test_ip4() -> IpAddr { + Ipv4(127, 0, 0, 1, next_test_port()) +} diff --git a/src/libcore/rt/uv/net.rs b/src/libcore/rt/uv/net.rs index 54823d4dbcf6..860c988b9c99 100644 --- a/src/libcore/rt/uv/net.rs +++ b/src/libcore/rt/uv/net.rs @@ -22,7 +22,7 @@ use super::super::io::net::ip::{IpAddr, Ipv4, Ipv6}; #[cfg(test)] use cell::Cell; #[cfg(test)] use unstable::run_in_bare_thread; #[cfg(test)] use super::super::thread::Thread; -#[cfg(test)] use super::super::test::next_test_port; +#[cfg(test)] use super::super::test::*; fn ip4_as_uv_ip4(addr: IpAddr, f: &fn(*sockaddr_in)) { match addr { @@ -359,7 +359,7 @@ fn connect_close() { let mut loop_ = Loop::new(); let mut tcp_watcher = { TcpWatcher::new(&mut loop_) }; // Connect to a port where nobody is listening - let addr = Ipv4(127, 0, 0, 1, next_test_port()); + let addr = next_test_ip4(); do tcp_watcher.connect(addr) |stream_watcher, status| { rtdebug!("tcp_watcher.connect!"); assert!(status.is_some()); @@ -377,7 +377,7 @@ fn listen() { static MAX: int = 10; let mut loop_ = Loop::new(); let mut server_tcp_watcher = { TcpWatcher::new(&mut loop_) }; - let addr = Ipv4(127, 0, 0, 1, next_test_port()); + let addr = next_test_ip4(); server_tcp_watcher.bind(addr); let loop_ = loop_; rtdebug!("listening"); diff --git a/src/libcore/rt/uvio.rs b/src/libcore/rt/uvio.rs index 2582ddf31051..92439a41b342 100644 --- a/src/libcore/rt/uvio.rs +++ b/src/libcore/rt/uvio.rs @@ -338,7 +338,7 @@ impl Stream for UvStream { fn test_simple_io_no_connect() { do run_in_newsched_task { let io = unsafe { local_sched::unsafe_borrow_io() }; - let addr = Ipv4(127, 0, 0, 1, next_test_port()); + let addr = next_test_ip4(); let maybe_chan = io.connect(addr); assert!(maybe_chan.is_none()); } @@ -347,7 +347,7 @@ fn test_simple_io_no_connect() { #[test] fn test_simple_tcp_server_and_client() { do run_in_newsched_task { - let addr = Ipv4(127, 0, 0, 1, next_test_port()); + let addr = next_test_ip4(); // Start the server first so it's listening when we connect do spawn_immediately { @@ -381,7 +381,7 @@ fn test_simple_tcp_server_and_client() { #[test] #[ignore(reason = "busted")] fn test_read_and_block() { do run_in_newsched_task { - let addr = Ipv4(127, 0, 0, 1, next_test_port()); + let addr = next_test_ip4(); do spawn_immediately { let io = unsafe { local_sched::unsafe_borrow_io() }; @@ -437,7 +437,7 @@ fn test_read_and_block() { #[test] fn test_read_read_read() { do run_in_newsched_task { - let addr = Ipv4(127, 0, 0, 1, next_test_port()); + let addr = next_test_ip4(); static MAX: uint = 5000000; do spawn_immediately {