core::rt: Use generated port numbers in tests
This commit is contained in:
parent
744ba627f3
commit
d24a3a4b01
4 changed files with 24 additions and 49 deletions
|
@ -27,3 +27,13 @@ pub fn run_in_newsched_task(f: ~fn()) {
|
||||||
sched.run();
|
sched.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a port number, starting at 9600, for use in tests
|
||||||
|
pub fn next_test_port() -> u16 {
|
||||||
|
unsafe {
|
||||||
|
return rust_dbg_next_port() as u16;
|
||||||
|
}
|
||||||
|
extern {
|
||||||
|
fn rust_dbg_next_port() -> ::libc::uintptr_t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,12 +19,10 @@ use super::{Loop, Watcher, Request, UvError, Buf, Callback, NativeHandle, NullCa
|
||||||
vec_to_uv_buf, vec_from_uv_buf};
|
vec_to_uv_buf, vec_from_uv_buf};
|
||||||
use super::super::io::net::ip::{IpAddr, Ipv4, Ipv6};
|
use super::super::io::net::ip::{IpAddr, Ipv4, Ipv6};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)] use cell::Cell;
|
||||||
use unstable::run_in_bare_thread;
|
#[cfg(test)] use unstable::run_in_bare_thread;
|
||||||
#[cfg(test)]
|
#[cfg(test)] use super::super::thread::Thread;
|
||||||
use super::super::thread::Thread;
|
#[cfg(test)] use super::super::test::next_test_port;
|
||||||
#[cfg(test)]
|
|
||||||
use cell::Cell;
|
|
||||||
|
|
||||||
fn ip4_as_uv_ip4(addr: IpAddr, f: &fn(*sockaddr_in)) {
|
fn ip4_as_uv_ip4(addr: IpAddr, f: &fn(*sockaddr_in)) {
|
||||||
match addr {
|
match addr {
|
||||||
|
@ -361,7 +359,7 @@ fn connect_close() {
|
||||||
let mut loop_ = Loop::new();
|
let mut loop_ = Loop::new();
|
||||||
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
|
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
|
||||||
// Connect to a port where nobody is listening
|
// Connect to a port where nobody is listening
|
||||||
let addr = Ipv4(127, 0, 0, 1, 2923);
|
let addr = Ipv4(127, 0, 0, 1, next_test_port());
|
||||||
do tcp_watcher.connect(addr) |stream_watcher, status| {
|
do tcp_watcher.connect(addr) |stream_watcher, status| {
|
||||||
rtdebug!("tcp_watcher.connect!");
|
rtdebug!("tcp_watcher.connect!");
|
||||||
assert!(status.is_some());
|
assert!(status.is_some());
|
||||||
|
@ -373,47 +371,13 @@ fn connect_close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[ignore(reason = "need a server to connect to")]
|
|
||||||
fn connect_read() {
|
|
||||||
do run_in_bare_thread() {
|
|
||||||
let mut loop_ = Loop::new();
|
|
||||||
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
|
|
||||||
let addr = Ipv4(127, 0, 0, 1, 2924);
|
|
||||||
do tcp_watcher.connect(addr) |stream_watcher, status| {
|
|
||||||
let mut stream_watcher = stream_watcher;
|
|
||||||
rtdebug!("tcp_watcher.connect!");
|
|
||||||
assert!(status.is_none());
|
|
||||||
let alloc: AllocCallback = |size| {
|
|
||||||
vec_to_uv_buf(vec::from_elem(size, 0))
|
|
||||||
};
|
|
||||||
do stream_watcher.read_start(alloc)
|
|
||||||
|stream_watcher, nread, buf, status| {
|
|
||||||
|
|
||||||
let buf = vec_from_uv_buf(buf);
|
|
||||||
rtdebug!("read cb!");
|
|
||||||
if status.is_none() {
|
|
||||||
let bytes = buf.unwrap();
|
|
||||||
rtdebug!("%s", bytes.slice(0, nread as uint).to_str());
|
|
||||||
} else {
|
|
||||||
rtdebug!("status after read: %s", status.get().to_str());
|
|
||||||
rtdebug!("closing");
|
|
||||||
stream_watcher.close(||());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loop_.run();
|
|
||||||
loop_.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn listen() {
|
fn listen() {
|
||||||
do run_in_bare_thread() {
|
do run_in_bare_thread() {
|
||||||
static MAX: int = 10;
|
static MAX: int = 10;
|
||||||
let mut loop_ = Loop::new();
|
let mut loop_ = Loop::new();
|
||||||
let mut server_tcp_watcher = { TcpWatcher::new(&mut loop_) };
|
let mut server_tcp_watcher = { TcpWatcher::new(&mut loop_) };
|
||||||
let addr = Ipv4(127, 0, 0, 1, 2925);
|
let addr = Ipv4(127, 0, 0, 1, next_test_port());
|
||||||
server_tcp_watcher.bind(addr);
|
server_tcp_watcher.bind(addr);
|
||||||
let loop_ = loop_;
|
let loop_ = loop_;
|
||||||
rtdebug!("listening");
|
rtdebug!("listening");
|
||||||
|
|
|
@ -19,9 +19,10 @@ use cell::{Cell, empty_cell};
|
||||||
use cast::transmute;
|
use cast::transmute;
|
||||||
use super::sched::{Scheduler, local_sched};
|
use super::sched::{Scheduler, local_sched};
|
||||||
|
|
||||||
#[cfg(test)] use super::sched::Task;
|
|
||||||
#[cfg(test)] use unstable::run_in_bare_thread;
|
|
||||||
#[cfg(test)] use uint;
|
#[cfg(test)] use uint;
|
||||||
|
#[cfg(test)] use unstable::run_in_bare_thread;
|
||||||
|
#[cfg(test)] use super::sched::Task;
|
||||||
|
#[cfg(test)] use super::test::next_test_port;
|
||||||
|
|
||||||
pub struct UvEventLoop {
|
pub struct UvEventLoop {
|
||||||
uvio: UvIoFactory
|
uvio: UvIoFactory
|
||||||
|
@ -340,7 +341,7 @@ fn test_simple_io_no_connect() {
|
||||||
let mut sched = ~UvEventLoop::new_scheduler();
|
let mut sched = ~UvEventLoop::new_scheduler();
|
||||||
let task = ~do Task::new(&mut sched.stack_pool) {
|
let task = ~do Task::new(&mut sched.stack_pool) {
|
||||||
let io = unsafe { local_sched::unsafe_borrow_io() };
|
let io = unsafe { local_sched::unsafe_borrow_io() };
|
||||||
let addr = Ipv4(127, 0, 0, 1, 2926);
|
let addr = Ipv4(127, 0, 0, 1, next_test_port());
|
||||||
let maybe_chan = io.connect(addr);
|
let maybe_chan = io.connect(addr);
|
||||||
assert!(maybe_chan.is_none());
|
assert!(maybe_chan.is_none());
|
||||||
};
|
};
|
||||||
|
@ -354,7 +355,7 @@ fn test_simple_io_no_connect() {
|
||||||
fn test_simple_tcp_server_and_client() {
|
fn test_simple_tcp_server_and_client() {
|
||||||
do run_in_bare_thread {
|
do run_in_bare_thread {
|
||||||
let mut sched = ~UvEventLoop::new_scheduler();
|
let mut sched = ~UvEventLoop::new_scheduler();
|
||||||
let addr = Ipv4(127, 0, 0, 1, 2929);
|
let addr = Ipv4(127, 0, 0, 1, next_test_port());
|
||||||
|
|
||||||
let client_task = ~do Task::new(&mut sched.stack_pool) {
|
let client_task = ~do Task::new(&mut sched.stack_pool) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -393,7 +394,7 @@ fn test_simple_tcp_server_and_client() {
|
||||||
fn test_read_and_block() {
|
fn test_read_and_block() {
|
||||||
do run_in_bare_thread {
|
do run_in_bare_thread {
|
||||||
let mut sched = ~UvEventLoop::new_scheduler();
|
let mut sched = ~UvEventLoop::new_scheduler();
|
||||||
let addr = Ipv4(127, 0, 0, 1, 2930);
|
let addr = Ipv4(127, 0, 0, 1, next_test_port());
|
||||||
|
|
||||||
let client_task = ~do Task::new(&mut sched.stack_pool) {
|
let client_task = ~do Task::new(&mut sched.stack_pool) {
|
||||||
let io = unsafe { local_sched::unsafe_borrow_io() };
|
let io = unsafe { local_sched::unsafe_borrow_io() };
|
||||||
|
@ -454,7 +455,7 @@ fn test_read_and_block() {
|
||||||
fn test_read_read_read() {
|
fn test_read_read_read() {
|
||||||
do run_in_bare_thread {
|
do run_in_bare_thread {
|
||||||
let mut sched = ~UvEventLoop::new_scheduler();
|
let mut sched = ~UvEventLoop::new_scheduler();
|
||||||
let addr = Ipv4(127, 0, 0, 1, 2931);
|
let addr = Ipv4(127, 0, 0, 1, next_test_port());
|
||||||
|
|
||||||
let client_task = ~do Task::new(&mut sched.stack_pool) {
|
let client_task = ~do Task::new(&mut sched.stack_pool) {
|
||||||
let io = unsafe { local_sched::unsafe_borrow_io() };
|
let io = unsafe { local_sched::unsafe_borrow_io() };
|
||||||
|
|
|
@ -170,7 +170,7 @@ rust_dbg_extern_identity_TwoDoubles(TwoDoubles u) {
|
||||||
extern "C" CDECL uintptr_t
|
extern "C" CDECL uintptr_t
|
||||||
rust_dbg_next_port() {
|
rust_dbg_next_port() {
|
||||||
static lock_and_signal dbg_port_lock;
|
static lock_and_signal dbg_port_lock;
|
||||||
static uintptr_t next_port = 9000;
|
static uintptr_t next_port = 9600;
|
||||||
scoped_lock with(dbg_port_lock);
|
scoped_lock with(dbg_port_lock);
|
||||||
uintptr_t this_port = next_port;
|
uintptr_t this_port = next_port;
|
||||||
next_port += 1;
|
next_port += 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue