Skip to content

Make integration tests fail on infeasible trajectories. #1127

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
96 changes: 35 additions & 61 deletions src-core/src/integration_tests/generate.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#[cfg(test)]
mod generate {
use std::fs;
use std::{
path::PathBuf,
thread::{self, JoinHandle},
};
use std::path::PathBuf;

use crate::{
file_management::{self, WritingResources},
Expand Down Expand Up @@ -35,13 +32,17 @@ mod generate {
fs::copy(original_traj.clone(), test_traj.clone()).unwrap();
let resources = WritingResources::new();
// if this succeeds, modified generated .traj is written to test_traj
generate_trajectories(&resources, &test_chor.clone(), vec![drive_type.to_string()]).await;
assert!(
generate_trajectories(&resources, &test_chor.clone(), drive_type.to_string()).await
);
// Generation should be identical IF on the same platform
// so we compare before/after the second generation
// this also checks that the first one produced a loadable .traj
let traj_after_first = fs::read_to_string(test_traj.clone()).unwrap();
let chor_after_first = fs::read_to_string(test_chor.clone()).unwrap();
generate_trajectories(&resources, &test_chor.clone(), vec![drive_type.to_string()]).await;
assert!(
generate_trajectories(&resources, &test_chor.clone(), drive_type.to_string()).await
);
let traj_after_second = fs::read_to_string(test_traj.clone()).unwrap();
let chor_after_second = fs::read_to_string(test_chor.clone()).unwrap();
assert!(traj_after_first == traj_after_second);
Expand All @@ -52,8 +53,8 @@ mod generate {
async fn generate_trajectories(
resources: &WritingResources,
project_path: &PathBuf,
mut trajectory_names: Vec<String>,
) {
trajectory_name: String,
) -> bool {
file_management::set_deploy_path(
&resources,
project_path
Expand All @@ -78,19 +79,8 @@ mod generate {
// ADDED: Cli doesn't write the upgraded project, but we want to test the project file writing
file_management::write_projectfile(&resources, project.clone()).await;

if trajectory_names.is_empty() {
trajectory_names = file_management::find_all_trajectories(&resources).await;
}

if trajectory_names.is_empty() {
tracing::error!("No trajectories found in the project directory");
return;
}

let mut thread_handles: Vec<JoinHandle<()>> = Vec::new();

// generate trajectories
for (i, trajectory_name) in trajectory_names.iter().enumerate() {
{
tracing::info!(
"Generating trajectory {:} for {:}",
trajectory_name,
Expand All @@ -105,56 +95,40 @@ mod generate {
let cln_project = project.clone();
let cln_resources = resources.clone();
let cln_trajectory_name = trajectory_name.clone();
let handle =
thread::spawn(
move || match generate(cln_project.clone(), trajectory, i as i64) {
Ok(new_trajectory) => {
let runtime = crate::tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed to build tokio runtime");
let write_result = runtime.block_on(
file_management::write_trajectory_file_immediately(
&cln_resources,
new_trajectory,
),
match generate(cln_project.clone(), trajectory, 0) {
Ok(new_trajectory) => {
let write_result = file_management::write_trajectory_file_immediately(
&cln_resources,
new_trajectory,
)
.await;
let ok = write_result.is_ok();
match write_result {
Ok(_) => {
tracing::info!(
"Successfully generated trajectory {:} for {:}",
cln_trajectory_name,
cln_project.name
);
match write_result {
Ok(_) => {
tracing::info!(
"Successfully generated trajectory {:} for {:}",
cln_trajectory_name,
cln_project.name
);
}
Err(e) => {
tracing::error!(
"Failed to write trajectory {:} for {:}: {:}",
cln_trajectory_name,
cln_project.name,
e
);
}
}
}
Err(e) => {
tracing::error!(
"Failed to generate trajectory {:}: {:}",
"Failed to write trajectory {:} for {:}: {:}",
cln_trajectory_name,
cln_project.name,
e
);
}
},
);

thread_handles.push(handle);
}

for handle in thread_handles {
match handle.join() {
Ok(_) => {}
}
ok
}
Err(e) => {
tracing::error!("Failed to join thread: {:?}", e);
tracing::error!(
"Failed to generate trajectory {:}: {:}",
cln_trajectory_name,
e
);
false
}
}
}
Expand Down
Loading