@@ -126,62 +126,56 @@ impl Drop for AsyncWatcher {
126
126
#[ cfg( test) ]
127
127
mod test_remote {
128
128
use std:: cell:: Cell ;
129
- use std:: rt:: test :: * ;
129
+ use std:: rt:: rtio :: Callback ;
130
130
use std:: rt:: thread:: Thread ;
131
131
use std:: rt:: tube:: Tube ;
132
- use std:: rt:: rtio:: EventLoop ;
133
- use std:: rt:: local:: Local ;
134
- use std:: rt:: sched:: Scheduler ;
135
132
133
+ use super :: * ;
134
+ use super :: super :: run_uv_loop;
135
+
136
+ // Make sure that we can fire watchers in remote threads
136
137
#[ test]
137
138
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
+ }
152
147
}
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
+
153
155
let thread = do Thread :: start {
154
- remote_cell . take ( ) . fire ( ) ;
156
+ watcher . take ( ) . fire ( ) ;
155
157
} ;
156
158
157
- assert ! ( tube. recv( ) == 1 ) ;
159
+ assert_eq ! ( tube. recv( ) , 1 ) ;
158
160
thread. join ( ) ;
159
161
}
160
162
}
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 ;
171
163
172
164
#[ test]
173
165
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 ( ) ;
185
178
}
179
+ assert ! ( unsafe { hits > 0 } ) ;
186
180
}
187
181
}
0 commit comments