Skip to content

Commit 6e17202

Browse files
committed
core::rt: Add next_test_ip4 for generating test addresses
1 parent a11c032 commit 6e17202

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/libcore/rt/test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use super::io::net::ip::{IpAddr, Ipv4};
12+
1113
// For setting up tests of the new scheduler
1214
pub fn run_in_newsched_task(f: ~fn()) {
1315
use cell::Cell;
@@ -53,3 +55,8 @@ pub fn next_test_port() -> u16 {
5355
fn rust_dbg_next_port() -> ::libc::uintptr_t;
5456
}
5557
}
58+
59+
/// Get a unique localhost:port pair starting at 9600
60+
pub fn next_test_ip4() -> IpAddr {
61+
Ipv4(127, 0, 0, 1, next_test_port())
62+
}

src/libcore/rt/uv/net.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use super::super::io::net::ip::{IpAddr, Ipv4, Ipv6};
2222
#[cfg(test)] use cell::Cell;
2323
#[cfg(test)] use unstable::run_in_bare_thread;
2424
#[cfg(test)] use super::super::thread::Thread;
25-
#[cfg(test)] use super::super::test::next_test_port;
25+
#[cfg(test)] use super::super::test::*;
2626

2727
fn ip4_as_uv_ip4(addr: IpAddr, f: &fn(*sockaddr_in)) {
2828
match addr {
@@ -359,7 +359,7 @@ fn connect_close() {
359359
let mut loop_ = Loop::new();
360360
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
361361
// Connect to a port where nobody is listening
362-
let addr = Ipv4(127, 0, 0, 1, next_test_port());
362+
let addr = next_test_ip4();
363363
do tcp_watcher.connect(addr) |stream_watcher, status| {
364364
rtdebug!("tcp_watcher.connect!");
365365
assert!(status.is_some());
@@ -377,7 +377,7 @@ fn listen() {
377377
static MAX: int = 10;
378378
let mut loop_ = Loop::new();
379379
let mut server_tcp_watcher = { TcpWatcher::new(&mut loop_) };
380-
let addr = Ipv4(127, 0, 0, 1, next_test_port());
380+
let addr = next_test_ip4();
381381
server_tcp_watcher.bind(addr);
382382
let loop_ = loop_;
383383
rtdebug!("listening");

src/libcore/rt/uvio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl Stream for UvStream {
338338
fn test_simple_io_no_connect() {
339339
do run_in_newsched_task {
340340
let io = unsafe { local_sched::unsafe_borrow_io() };
341-
let addr = Ipv4(127, 0, 0, 1, next_test_port());
341+
let addr = next_test_ip4();
342342
let maybe_chan = io.connect(addr);
343343
assert!(maybe_chan.is_none());
344344
}
@@ -347,7 +347,7 @@ fn test_simple_io_no_connect() {
347347
#[test]
348348
fn test_simple_tcp_server_and_client() {
349349
do run_in_newsched_task {
350-
let addr = Ipv4(127, 0, 0, 1, next_test_port());
350+
let addr = next_test_ip4();
351351

352352
// Start the server first so it's listening when we connect
353353
do spawn_immediately {
@@ -381,7 +381,7 @@ fn test_simple_tcp_server_and_client() {
381381
#[test] #[ignore(reason = "busted")]
382382
fn test_read_and_block() {
383383
do run_in_newsched_task {
384-
let addr = Ipv4(127, 0, 0, 1, next_test_port());
384+
let addr = next_test_ip4();
385385

386386
do spawn_immediately {
387387
let io = unsafe { local_sched::unsafe_borrow_io() };
@@ -437,7 +437,7 @@ fn test_read_and_block() {
437437
#[test]
438438
fn test_read_read_read() {
439439
do run_in_newsched_task {
440-
let addr = Ipv4(127, 0, 0, 1, next_test_port());
440+
let addr = next_test_ip4();
441441
static MAX: uint = 5000000;
442442

443443
do spawn_immediately {

0 commit comments

Comments
 (0)