Skip to content

Commit 47e91d2

Browse files
Fixed tests
1 parent fb6d40a commit 47e91d2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/dispatcher.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ mod tests {
152152
use event_loop::SENDER;
153153
use protocol::{ThriftMessage, ThriftMessageType};
154154
use binary_protocol::BinaryDeserializer;
155+
use std::sync::mpsc::channel;
155156
use util;
157+
use std::thread;
158+
use std::time::Duration;
156159

157160
#[test]
158161
fn should_create_server_dispatcher() {
@@ -164,19 +167,32 @@ mod tests {
164167
fn should_start_server() {
165168
let addr: SocketAddr = "127.0.0.1:5955".parse().unwrap();
166169
let (handle_server, server) = Dispatcher::spawn(Role::Server(addr.clone())).unwrap();
170+
thread::sleep(Duration::from_millis(30));
167171
let (handle_client, client) = Dispatcher::spawn(Role::Client(addr.clone())).unwrap();
168172

169173
let buf = util::create_empty_thrift_message("foobar123", ThriftMessageType::Call);
170174

171175
let (res, future) = Future::<(ThriftMessage, BinaryDeserializer<Cursor<Vec<u8>>>)>::channel();
172176
client.send(Incoming::Call("foobar123".to_string(), buf, res)).unwrap();
173177

178+
let (res_tx, res_rx) = channel();
179+
let cloned = res_tx.clone();
174180
future.and_then(move |(msg, de)| {
175181
println!("[test]: Received: {:?}", msg);
176182
SENDER.clone().send(Message::Shutdown);
183+
res_tx.send(0);
177184
Async::Ok(())
178185
});
179186

187+
thread::spawn(move || -> Result<(), ()> {
188+
thread::sleep(Duration::from_millis(3000));
189+
SENDER.clone().send(Message::Shutdown);
190+
panic!("Test timeout was hit. This means the Reactor did not shutdown and a response was not received.");
191+
cloned.send(1);
192+
});
193+
180194
Reactor::run().join();
195+
196+
assert_eq!(res_rx.recv().unwrap(), 0);
181197
}
182198
}

src/reactor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,11 @@ impl Reactor {
366366
self.connections.get_mut(&id).expect("connection was not found #2").write(&*data);
367367
},
368368
Message::Shutdown => {
369+
println!("Shutting down...");
369370
event_loop.shutdown();
370371
},
371372
Message::Connect(addr, id_tx, tx) => {
372-
let mut mio_stream = TcpStream::connect(&addr).expect("MIO ERR");
373+
let mut mio_stream = TcpStream::connect(&addr)?;
373374
let new_token = Token(self.current_token);
374375
id_tx.send(Id(new_token));
375376
let mut conn = Connection::new((mio_stream, addr), new_token, tx);

0 commit comments

Comments
 (0)