Skip to content

Commit

Permalink
More coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
garious committed Feb 18, 2018
1 parent 831e2cb commit 4c94754
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/historian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Historian {
pub thread_hdl: JoinHandle<(Event, EventThreadExitReason)>,
}

#[derive(Debug, PartialEq, Eq)]
pub enum EventThreadExitReason {
RecvDisconnected,
SendDisconnected,
Expand All @@ -34,14 +35,9 @@ fn drain_queue(
let e = Event {
end_hash,
num_hashes,
data: data.clone(),
data,
};
if let Err(_) = sender.send(e) {
let e = Event {
end_hash,
num_hashes,
data,
};
if let Err(_) = sender.send(e.clone()) {
return Err((e, EventThreadExitReason::SendDisconnected));
}
num_hashes = 0;
Expand Down Expand Up @@ -120,6 +116,23 @@ mod tests {
let e1 = hist.receiver.recv().unwrap();
assert_eq!(e1.data, data);

drop(hist.sender);
assert_eq!(
hist.thread_hdl.join().unwrap().1,
EventThreadExitReason::RecvDisconnected
);

verify_slice(&[e0, e1], 0);
}

#[test]
fn test_historian_closed_sender() {
let hist = Historian::new(0);
drop(hist.receiver);
hist.sender.send(EventData::Tick).unwrap();
assert_eq!(
hist.thread_hdl.join().unwrap().1,
EventThreadExitReason::SendDisconnected
);
}
}

0 comments on commit 4c94754

Please sign in to comment.