use crate::error::NanonisError;
use std::time::Duration;
pub trait Job {
type Output;
fn run(&mut self, timeout: Duration) -> Result<Self::Output, NanonisError>;
}
#[cfg(test)]
mod tests {
use super::*;
struct TestJob {
should_succeed: bool,
}
impl Job for TestJob {
type Output = String;
fn run(&mut self, _timeout: Duration) -> Result<Self::Output, NanonisError> {
if self.should_succeed {
Ok("success".to_string())
} else {
Err(NanonisError::Timeout)
}
}
}
#[test]
fn test_job_success() {
let mut job = TestJob {
should_succeed: true,
};
let result = job.run(Duration::from_secs(1)).unwrap();
assert_eq!(result, "success");
}
#[test]
fn test_job_failure() {
let mut job = TestJob {
should_succeed: false,
};
let result = job.run(Duration::from_secs(1));
assert!(result.is_err());
}
}