Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call env.stop() on finish #2

Merged
merged 3 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub trait Environment {
/// And the config file's path to this environment if it's find, it's defined
/// by the `env_config_file` field in the root config toml, and the default
/// value is `config.toml`.
async fn start(&self, mode: &str, config: Option<String>) -> Self::DB;
async fn start(&self, env: &str, config: Option<String>) -> Self::DB;

/// Stop one [`Database`].
async fn stop(&self, mode: &str, database: Self::DB);
async fn stop(&self, env: &str, database: Self::DB);
}
21 changes: 12 additions & 9 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{config::Config, environment::Environment};
/// For more detailed explaination, refer to crate level documentment.
pub struct Runner<E: Environment> {
config: Config,
env: Arc<E>,
env_controller: Arc<E>,
}

impl<E: Environment> Runner<E> {
Expand All @@ -53,21 +53,26 @@ impl<E: Environment> Runner<E> {

Ok(Self {
config,
env: Arc::new(env),
env_controller: Arc::new(env),
})
}

pub async fn new_with_config(config: Config, env: E) -> Result<Self> {
Ok(Self {
config,
env: Arc::new(env),
env_controller: Arc::new(env),
})
}

pub async fn run(&self) -> Result<()> {
let environments = self.collect_env().await?;
for env in environments {
self.run_env(env).await?;
// todo: read env config
let db = self.env_controller.start(&env, None).await;
if let Err(e) = self.run_env(&env, &db).await {
println!("Environment {} run failed with error {:?}", env, e);
}
self.env_controller.stop(&env, db).await;
}

Ok(())
Expand All @@ -87,10 +92,8 @@ impl<E: Environment> Runner<E> {
Ok(result)
}

async fn run_env(&self, env: String) -> Result<()> {
// todo: read env config
let db = self.env.start(&env, None).await;
let case_paths = self.collect_case_paths(&env).await?;
async fn run_env(&self, env: &str, db: &E::DB) -> Result<()> {
let case_paths = self.collect_case_paths(env).await?;
let mut diff_cases = vec![];
let start = Instant::now();
for path in case_paths {
Expand All @@ -100,7 +103,7 @@ impl<E: Environment> Runner<E> {
let mut output_file = Self::open_output_file(&output_path).await?;

let timer = Instant::now();
case.execute(&db, &mut output_file).await?;
case.execute(db, &mut output_file).await?;
let elapsed = timer.elapsed();

output_file.flush().await?;
Expand Down