From d05e7e031ba436a7f15c1d1684a3a9e3e8b61107 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 18 Jan 2016 00:24:20 +0100 Subject: [PATCH] Basic queue test --- src/queue.rs | 14 ++++++++++++++ util/src/io/service.rs | 14 +++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/queue.rs b/src/queue.rs index a51d3014c..9af6294a7 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -229,3 +229,17 @@ impl Drop for BlockQueue { } } +#[cfg(test)] +mod tests { + use util::*; + use spec::*; + use queue::*; + + #[test] + fn test_block_queue() { + // TODO better test + let spec = Spec::new_test(); + let engine = spec.to_engine().unwrap(); + let _ = BlockQueue::new(Arc::new(engine), IoChannel::disconnected()); + } +} diff --git a/util/src/io/service.rs b/util/src/io/service.rs index dee7603d7..4a96d19a7 100644 --- a/util/src/io/service.rs +++ b/util/src/io/service.rs @@ -151,14 +151,22 @@ impl Handler for IoManager where Message: Send + 'static { /// Allows sending messages into the event loop. All the IO handlers will get the message /// in the `message` callback. pub struct IoChannel where Message: Send { - channel: Sender> + channel: Option>> } impl IoChannel where Message: Send { + /// Send a msessage through the channel pub fn send(&self, message: Message) -> Result<(), IoError> { - try!(self.channel.send(IoMessage::UserMessage(message))); + if let Some(ref channel) = self.channel { + try!(channel.send(IoMessage::UserMessage(message))); + } Ok(()) } + + /// Create a new channel to connected to event loop. + pub fn disconnected() -> IoChannel { + IoChannel { channel: None } + } } /// General IO Service. Starts an event loop and dispatches IO requests. @@ -198,7 +206,7 @@ impl IoService where Message: Send + 'static { /// Create a new message channel pub fn channel(&mut self) -> IoChannel { - IoChannel { channel: self.host_channel.clone() } + IoChannel { channel: Some(self.host_channel.clone()) } } }