1use crate::error::NanonisError;
2use std::time::Duration;
3
4pub trait Job {
9 type Output;
11
12 fn run(&mut self, timeout: Duration) -> Result<Self::Output, NanonisError>;
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23
24 struct TestJob {
25 should_succeed: bool,
26 }
27
28 impl Job for TestJob {
29 type Output = String;
30
31 fn run(&mut self, _timeout: Duration) -> Result<Self::Output, NanonisError> {
32 if self.should_succeed {
33 Ok("success".to_string())
34 } else {
35 Err(NanonisError::Timeout)
36 }
37 }
38 }
39
40 #[test]
41 fn test_job_success() {
42 let mut job = TestJob {
43 should_succeed: true,
44 };
45 let result = job.run(Duration::from_secs(1)).unwrap();
46 assert_eq!(result, "success");
47 }
48
49 #[test]
50 fn test_job_failure() {
51 let mut job = TestJob {
52 should_succeed: false,
53 };
54 let result = job.run(Duration::from_secs(1));
55 assert!(result.is_err());
56 }
57}