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

[wip]chore: fix cucumber test #6087

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 19 additions & 16 deletions integration_tests/tests/cucumber.rs
Expand Up @@ -41,14 +41,17 @@ pub mod steps;
pub const LOG_TARGET: &str = "cucumber";
pub const LOG_TARGET_STDOUT: &str = "stdout";

fn flush_stdout(buffer: &Arc<Mutex<Vec<u8>>>) {
fn try_flush_stdout(buffer: &Arc<Mutex<Vec<u8>>>) {
// After each test we flush the stdout to the logs.
info!(
target: LOG_TARGET_STDOUT,
"{}",
str::from_utf8(&buffer.lock().unwrap()).unwrap()
);
buffer.lock().unwrap().clear();
let mut lock = buffer.try_lock();
if let Ok(ref mut mutex) = lock {
info!(
target: LOG_TARGET_STDOUT,
"{}",
str::from_utf8(mutex).unwrap_or("")
);
mutex.clear();
}
}

fn main() {
Expand Down Expand Up @@ -78,7 +81,7 @@ fn main() {
.after(move |_feature, _rule, scenario, ev, maybe_world| {
let stdout_buffer = stdout_buffer_clone.clone();
Box::pin(async move {
flush_stdout(&stdout_buffer);
try_flush_stdout(&stdout_buffer);
match ev {
ScenarioFinished::StepFailed(_capture_locations, _location, _error) => {
error!(target: LOG_TARGET, "Scenario failed");
Expand Down Expand Up @@ -117,17 +120,17 @@ fn main() {
});

// If by any chance we have anything in the stdout buffer just log it.
flush_stdout(&stdout_buffer);
try_flush_stdout(&stdout_buffer);

// Move the logs to the temp dir
let crate_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let log_dir = crate_root.join("log");
let test_run_dir = crate_root.join(format!("tests/temp/cucumber_{}/logs", process::id()));
fs::create_dir_all(&test_run_dir).unwrap();

for entry in fs::read_dir(log_dir).unwrap() {
let file = entry.unwrap();
fs::copy(file.path(), test_run_dir.join(file.file_name())).unwrap();
fs::remove_file(file.path()).unwrap();
}
// fs::create_dir_all(&test_run_dir).unwrap();
//
// for entry in fs::read_dir(log_dir).unwrap() {
// let file = entry.unwrap();
// fs::copy(file.path(), test_run_dir.join(file.file_name())).unwrap();
// fs::remove_file(file.path()).unwrap();
// }
Comment on lines +129 to +135
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this? Is it because of unwrap failing the test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, same question here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is related

}