|
|
@ -144,26 +144,11 @@ impl< |
|
|
|
RegularSetupCore<SR, L, B>: SetupCore<R, Setup<SR, L, B, Rs, As>>,
|
|
|
|
{
|
|
|
|
let recorder = Recorder::default();
|
|
|
|
let drain = recorder.clone();
|
|
|
|
let log = Rc::new(slog::Logger::root(
|
|
|
|
drain,
|
|
|
|
o!("resource" => format!("{resource:?}")),
|
|
|
|
));
|
|
|
|
|
|
|
|
let result = self.1.add(&log, resource, force_run).await;
|
|
|
|
match &result {
|
|
|
|
Ok((_, did_run)) => {
|
|
|
|
if *did_run {
|
|
|
|
let log = recorder.to_string(slog::Level::Info);
|
|
|
|
if !log.is_empty() {
|
|
|
|
self.0.writeln(3, &log);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.0.write(3, ".");
|
|
|
|
}
|
|
|
|
Err(_) => self.0.writeln(2, &recorder.to_string(slog::Level::Trace)),
|
|
|
|
}
|
|
|
|
let result = {
|
|
|
|
let log = Rc::new(slog::Logger::root(recorder.clone(), o!()));
|
|
|
|
self.1.add(&log, resource, force_run).await
|
|
|
|
};
|
|
|
|
self.log_result(recorder, result.as_ref().map(|(_, did_run)| *did_run));
|
|
|
|
result
|
|
|
|
}
|
|
|
|
pub async fn add<R: AddableResource>(&self, resource: R) -> AddResult<R>
|
|
|
@ -186,36 +171,43 @@ impl< |
|
|
|
RegularSetupCore<SR, L, B>: SymbolRunner,
|
|
|
|
{
|
|
|
|
let recorder = Recorder::default();
|
|
|
|
let drain = recorder.clone();
|
|
|
|
let log = Rc::new(slog::Logger::root(
|
|
|
|
drain,
|
|
|
|
o!("symbol" => format!("{symbol:?}")),
|
|
|
|
));
|
|
|
|
|
|
|
|
let result = (self.1).0.core.run_symbol(&symbol, &log, force).await;
|
|
|
|
self.0.write(
|
|
|
|
3,
|
|
|
|
&recorder.to_string(if result.is_ok() {
|
|
|
|
slog::Level::Info
|
|
|
|
} else {
|
|
|
|
slog::Level::Trace
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
let result = {
|
|
|
|
let log = Rc::new(slog::Logger::root(
|
|
|
|
recorder.clone(),
|
|
|
|
o!("symbol" => format!("{symbol:?}")),
|
|
|
|
));
|
|
|
|
(self.1).0.core.run_symbol(&symbol, &log, force).await
|
|
|
|
};
|
|
|
|
self.log_result(recorder, result.as_ref().copied());
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_result(&self, recorder: Recorder, result: Result<bool, &Box<dyn Error>>) {
|
|
|
|
let log = match result {
|
|
|
|
Ok(false) => String::new(),
|
|
|
|
Ok(true) => recorder.into_string(slog::Level::Info),
|
|
|
|
Err(e) => recorder.into_string(slog::Level::Trace),
|
|
|
|
};
|
|
|
|
if log.is_empty() {
|
|
|
|
self.0.write(3, ".");
|
|
|
|
} else {
|
|
|
|
self.0.writeln(3, &log);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::SymbolRunner;
|
|
|
|
use crate::async_utils::run;
|
|
|
|
use crate::loggers::StoringLogger;
|
|
|
|
use crate::loggers::{Entry, StoringLogger};
|
|
|
|
use crate::resources::{FromArtifact, FromResource, Resource};
|
|
|
|
use crate::symbols::Symbol;
|
|
|
|
use crate::to_artifact::ToArtifact;
|
|
|
|
use crate::{ImplementationBuilder, ResourceLocator, Setup};
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use slog::Logger;
|
|
|
|
use regex::Regex;
|
|
|
|
use slog::{info, Logger};
|
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt::Debug;
|
|
|
@ -230,9 +222,10 @@ mod test { |
|
|
|
async fn run_symbol<S: Symbol + Debug>(
|
|
|
|
&self,
|
|
|
|
symbol: &S,
|
|
|
|
_logger: &Logger,
|
|
|
|
logger: &Logger,
|
|
|
|
force: bool,
|
|
|
|
) -> Result<bool, Box<dyn Error>> {
|
|
|
|
info!(logger, "run");
|
|
|
|
let run = force || !symbol.target_reached().await?;
|
|
|
|
if run {
|
|
|
|
*self.count.borrow_mut() += 1;
|
|
|
@ -342,26 +335,62 @@ mod test { |
|
|
|
Resources,
|
|
|
|
Artifacts,
|
|
|
|
>,
|
|
|
|
StoringLogger,
|
|
|
|
) {
|
|
|
|
let count = Rc::new(RefCell::new(0));
|
|
|
|
let runner = TestSymbolRunner {
|
|
|
|
count: Rc::clone(&count),
|
|
|
|
};
|
|
|
|
(count, Setup::new_with(runner, StoringLogger::new()))
|
|
|
|
let logger = StoringLogger::new();
|
|
|
|
(count, Setup::new_with(runner, logger.clone()), logger)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn correctly_uses_force() {
|
|
|
|
run(async {
|
|
|
|
let (count, setup) = get_setup();
|
|
|
|
let (count, setup, _) = get_setup();
|
|
|
|
setup.add(TestResource("A", "b")).await.unwrap();
|
|
|
|
assert_eq!(*count.borrow(), 2);
|
|
|
|
setup.add(TestResource("A", "b")).await.unwrap();
|
|
|
|
assert_eq!(*count.borrow(), 2);
|
|
|
|
|
|
|
|
let (count, setup) = get_setup();
|
|
|
|
let (count, setup, _) = get_setup();
|
|
|
|
setup.add(TestResource("A", "B")).await.unwrap();
|
|
|
|
assert_eq!(*count.borrow(), 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_reached_symbol() {
|
|
|
|
run(async {
|
|
|
|
let (count, setup, log) = get_setup();
|
|
|
|
let did_run = setup
|
|
|
|
.run_symbol(TestSymbol { reached: true }, false)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
drop(setup);
|
|
|
|
assert!(!did_run);
|
|
|
|
assert_eq!(*count.borrow(), 0);
|
|
|
|
assert_eq!(log.release(), vec![Entry(3, ".".into())]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_not_reached_symbol() {
|
|
|
|
run(async {
|
|
|
|
let (count, setup, log) = get_setup();
|
|
|
|
let did_run = setup
|
|
|
|
.run_symbol(TestSymbol { reached: false }, false)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
drop(setup);
|
|
|
|
assert!(did_run);
|
|
|
|
assert_eq!(*count.borrow(), 1);
|
|
|
|
let log = log.release();
|
|
|
|
assert_eq!(log.len(), 1);
|
|
|
|
assert_eq!(log[0].0, 3);
|
|
|
|
let re = Regex::new(r"^symbol: TestSymbol \{ reached: false \}\n \w+ \d{1,2} \d{2}:\d{2}:\d{2}.\d{3} INFO run\n$").unwrap();
|
|
|
|
assert!(re.is_match(&log[0].1));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|