Skip to content

Commit c654b0e

Browse files
committed
Update all uv tests to pass again
1 parent 58278ca commit c654b0e

File tree

7 files changed

+706
-1341
lines changed

7 files changed

+706
-1341
lines changed

src/librustuv/addrinfo.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,28 +189,27 @@ pub fn accum_addrinfo(addr: &Addrinfo) -> ~[ai::Info] {
189189

190190
#[cfg(test)]
191191
mod test {
192-
use Loop;
193192
use std::rt::io::net::ip::{SocketAddr, Ipv4Addr};
194193
use super::*;
194+
use super::super::run_uv_loop;
195195

196196
#[test]
197197
fn getaddrinfo_test() {
198-
let mut loop_ = Loop::new();
199-
let mut req = GetAddrInfoRequest::new();
200-
do req.getaddrinfo(&loop_, Some("localhost"), None, None) |_, addrinfo, _| {
201-
let sockaddrs = accum_addrinfo(addrinfo);
202-
let mut found_local = false;
203-
let local_addr = &SocketAddr {
204-
ip: Ipv4Addr(127, 0, 0, 1),
205-
port: 0
206-
};
207-
for addr in sockaddrs.iter() {
208-
found_local = found_local || addr.address == *local_addr;
198+
do run_uv_loop |l| {
199+
match GetAddrInfoRequest::run(l, Some("localhost"), None, None) {
200+
Ok(infos) => {
201+
let mut found_local = false;
202+
let local_addr = &SocketAddr {
203+
ip: Ipv4Addr(127, 0, 0, 1),
204+
port: 0
205+
};
206+
for addr in infos.iter() {
207+
found_local = found_local || addr.address == *local_addr;
208+
}
209+
assert!(found_local);
210+
}
211+
Err(e) => fail!("{:?}", e),
209212
}
210-
assert!(found_local);
211213
}
212-
loop_.run();
213-
loop_.close();
214-
req.delete();
215214
}
216215
}

src/librustuv/async.rs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -126,62 +126,56 @@ impl Drop for AsyncWatcher {
126126
#[cfg(test)]
127127
mod test_remote {
128128
use std::cell::Cell;
129-
use std::rt::test::*;
129+
use std::rt::rtio::Callback;
130130
use std::rt::thread::Thread;
131131
use std::rt::tube::Tube;
132-
use std::rt::rtio::EventLoop;
133-
use std::rt::local::Local;
134-
use std::rt::sched::Scheduler;
135132

133+
use super::*;
134+
use super::super::run_uv_loop;
135+
136+
// Make sure that we can fire watchers in remote threads
136137
#[test]
137138
fn test_uv_remote() {
138-
do run_in_mt_newsched_task {
139-
let mut tube = Tube::new();
140-
let tube_clone = tube.clone();
141-
let remote_cell = Cell::new_empty();
142-
do Local::borrow |sched: &mut Scheduler| {
143-
let tube_clone = tube_clone.clone();
144-
let tube_clone_cell = Cell::new(tube_clone);
145-
let remote = do sched.event_loop.remote_callback {
146-
// This could be called multiple times
147-
if !tube_clone_cell.is_empty() {
148-
tube_clone_cell.take().send(1);
149-
}
150-
};
151-
remote_cell.put_back(remote);
139+
struct MyCallback(Option<Tube<int>>);
140+
impl Callback for MyCallback {
141+
fn call(&mut self) {
142+
// this can get called more than once, but we only want to send
143+
// once
144+
if self.is_some() {
145+
self.take_unwrap().send(1);
146+
}
152147
}
148+
}
149+
150+
do run_uv_loop |l| {
151+
let mut tube = Tube::new();
152+
let cb = ~MyCallback(Some(tube.clone()));
153+
let watcher = Cell::new(AsyncWatcher::new(l, cb as ~Callback));
154+
153155
let thread = do Thread::start {
154-
remote_cell.take().fire();
156+
watcher.take().fire();
155157
};
156158

157-
assert!(tube.recv() == 1);
159+
assert_eq!(tube.recv(), 1);
158160
thread.join();
159161
}
160162
}
161-
}
162-
163-
#[cfg(test)]
164-
mod test {
165-
166-
use super::*;
167-
use Loop;
168-
use std::unstable::run_in_bare_thread;
169-
use std::rt::thread::Thread;
170-
use std::cell::Cell;
171163

172164
#[test]
173165
fn smoke_test() {
174-
do run_in_bare_thread {
175-
let mut loop_ = Loop::new();
176-
let watcher = AsyncWatcher::new(&mut loop_, |w, _| w.close(||()) );
177-
let watcher_cell = Cell::new(watcher);
178-
let thread = do Thread::start {
179-
let mut watcher = watcher_cell.take();
180-
watcher.send();
181-
};
182-
loop_.run();
183-
loop_.close();
184-
thread.join();
166+
static mut hits: uint = 0;
167+
168+
struct MyCallback;
169+
impl Callback for MyCallback {
170+
fn call(&mut self) {
171+
unsafe { hits += 1; }
172+
}
173+
}
174+
175+
do run_uv_loop |l| {
176+
let mut watcher = AsyncWatcher::new(l, ~MyCallback as ~Callback);
177+
watcher.fire();
185178
}
179+
assert!(unsafe { hits > 0 });
186180
}
187181
}

0 commit comments

Comments
 (0)