core::rt: Add next_test_ip4 for generating test addresses
This commit is contained in:
parent
a11c032f36
commit
6e17202ff4
3 changed files with 14 additions and 7 deletions
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue