1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pub use chan_signal::Signal;
pub use chan::{Sender, Receiver};
use {MaridError};
pub trait Runner {
fn run(self: Box<Self>, signals: Receiver<Signal>) -> Result<(), MaridError>;
fn setup(&mut self) -> Result<(), MaridError>;
}
pub trait Process {
type Error;
fn ready(&self) -> Result<(), Self::Error>;
fn wait(&self) -> Result<(), Self::Error>;
fn signal(&self, signal: Signal);
}
#[cfg(test)]
mod tests {
use {Signal, Process};
use test_helpers::{TestProcess, TestRunner};
use chan;
#[test]
fn test_runner_and_thread() {
let (sn, rc) = chan::sync(1);
let runner = TestRunner::new(0, sn);
let thread = TestProcess::new(runner);
assert!(thread.ready().is_ok());
thread.signal(Signal::INT);
assert!(thread.wait().is_ok());
assert!(rc.recv().unwrap());
}
#[test]
fn test_signal() {
let (sn, rc) = chan::sync(1);
let runner = TestRunner::new(0, sn);
let thread = TestProcess::new(runner);
assert!(thread.ready().is_ok());
thread.signal(Signal::HUP);
assert!(thread.wait().is_err());
assert!(!rc.recv().unwrap());
}
}