diff --git a/src/lib.rs b/src/lib.rs index fbacb57..a45bd21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ pub use exit::{ExitCode, ExitCodeError}; /// Main entrypoint into the program pub fn run() { let opt = opt::Opt::load(); - let logger = init_logging(&opt.common); + let logger = init_logging(&opt.common, opt.subcommand.is_remote_process()); if let Err(x) = opt.subcommand.run(opt.common) { if !x.is_silent() { error!("Exiting due to error: {}", x); @@ -28,7 +28,7 @@ pub fn run() { } } -fn init_logging(opt: &opt::CommonOpt) -> flexi_logger::LoggerHandle { +fn init_logging(opt: &opt::CommonOpt, is_remote_process: bool) -> flexi_logger::LoggerHandle { use flexi_logger::{FileSpec, LevelFilter, LogSpecification, Logger}; let modules = &["distant", "distant_core"]; @@ -48,8 +48,15 @@ fn init_logging(opt: &opt::CommonOpt) -> flexi_logger::LoggerHandle { }, ); - // If quiet, we suppress all output - if opt.quiet { + // If quiet, we suppress all logging output + // + // NOTE: For a process request, unless logging to a file, we also suppress logging output + // to avoid unexpected results when being treated like a process + // + // Without this, CI tests can sporadically fail when getting the exit code of a + // process because an error log is provided about failing to broadcast a response + // on the client side + if opt.quiet || (is_remote_process && opt.log_file.is_some()) { builder.module(module, LevelFilter::Off); } } diff --git a/src/opt.rs b/src/opt.rs index 23b41ce..e45c725 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -109,6 +109,19 @@ impl Subcommand { Ok(()) } + + /// Returns true if subcommand simplifies to acting as a proxy for a remote process + pub fn is_remote_process(&self) -> bool { + match self { + Self::Action(cmd) => cmd + .operation + .as_ref() + .map(|req| req.is_proc_run()) + .unwrap_or_default(), + Self::Lsp(_) => true, + _ => false, + } + } } /// Represents the format for data communicated to & from the client diff --git a/tests/cli/action/file_append.rs b/tests/cli/action/file_append.rs index bd7d93c..36783e6 100644 --- a/tests/cli/action/file_append.rs +++ b/tests/cli/action/file_append.rs @@ -41,6 +41,9 @@ fn should_report_ok_when_done(mut action_cmd: Command) { .stdout("") .stderr(""); + // NOTE: We wait a little bit to give the OS time to fully write to file + std::thread::sleep(std::time::Duration::from_millis(100)); + // Because we're talking to a local server, we can verify locally file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS)); } @@ -98,6 +101,9 @@ fn should_support_json_output(mut action_cmd: Command) { res.payload[0] ); + // NOTE: We wait a little bit to give the OS time to fully write to file + std::thread::sleep(std::time::Duration::from_millis(100)); + // Because we're talking to a local server, we can verify locally file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS)); } diff --git a/tests/cli/action/file_append_text.rs b/tests/cli/action/file_append_text.rs index 80e2203..2e7bc02 100644 --- a/tests/cli/action/file_append_text.rs +++ b/tests/cli/action/file_append_text.rs @@ -41,6 +41,9 @@ fn should_report_ok_when_done(mut action_cmd: Command) { .stdout("") .stderr(""); + // NOTE: We wait a little bit to give the OS time to fully write to file + std::thread::sleep(std::time::Duration::from_millis(100)); + // Because we're talking to a local server, we can verify locally file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS)); } @@ -98,6 +101,9 @@ fn should_support_json_output(mut action_cmd: Command) { res.payload[0] ); + // NOTE: We wait a little bit to give the OS time to fully write to file + std::thread::sleep(std::time::Duration::from_millis(100)); + // Because we're talking to a local server, we can verify locally file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS)); } diff --git a/tests/cli/action/file_write.rs b/tests/cli/action/file_write.rs index e2f79ca..add4fbe 100644 --- a/tests/cli/action/file_write.rs +++ b/tests/cli/action/file_write.rs @@ -30,6 +30,9 @@ fn should_report_ok_when_done(mut action_cmd: Command) { .stdout("") .stderr(""); + // NOTE: We wait a little bit to give the OS time to fully write to file + std::thread::sleep(std::time::Duration::from_millis(100)); + // Because we're talking to a local server, we can verify locally file.assert(FILE_CONTENTS); } @@ -81,6 +84,9 @@ fn should_support_json_output(mut action_cmd: Command) { res.payload[0] ); + // NOTE: We wait a little bit to give the OS time to fully write to file + std::thread::sleep(std::time::Duration::from_millis(100)); + // Because we're talking to a local server, we can verify locally file.assert(FILE_CONTENTS); } diff --git a/tests/cli/action/file_write_text.rs b/tests/cli/action/file_write_text.rs index 35de2dc..b238ae8 100644 --- a/tests/cli/action/file_write_text.rs +++ b/tests/cli/action/file_write_text.rs @@ -35,6 +35,9 @@ fn should_report_ok_when_done(mut action_cmd: Command) { .stdout("") .stderr(""); + // NOTE: We wait a little bit to give the OS time to fully write to file + std::thread::sleep(std::time::Duration::from_millis(100)); + // Because we're talking to a local server, we can verify locally file.assert(FILE_CONTENTS); } @@ -91,6 +94,9 @@ fn should_support_json_output(mut action_cmd: Command) { res.payload[0] ); + // NOTE: We wait a little bit to give the OS time to fully write to file + std::thread::sleep(std::time::Duration::from_millis(100)); + // Because we're talking to a local server, we can verify locally file.assert(FILE_CONTENTS); }