Update remote process execution to automatically disabling logging to console; add sleep before checking file write/append results to account for delays from OS

pull/47/head
Chip Senkbeil 3 years ago
parent 4eb15bfe1e
commit 35fa1197da
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -16,7 +16,7 @@ pub use exit::{ExitCode, ExitCodeError};
/// Main entrypoint into the program /// Main entrypoint into the program
pub fn run() { pub fn run() {
let opt = opt::Opt::load(); 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 let Err(x) = opt.subcommand.run(opt.common) {
if !x.is_silent() { if !x.is_silent() {
error!("Exiting due to error: {}", x); 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}; use flexi_logger::{FileSpec, LevelFilter, LogSpecification, Logger};
let modules = &["distant", "distant_core"]; 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 quiet, we suppress all logging output
if opt.quiet { //
// 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); builder.module(module, LevelFilter::Off);
} }
} }

@ -109,6 +109,19 @@ impl Subcommand {
Ok(()) 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 /// Represents the format for data communicated to & from the client

@ -41,6 +41,9 @@ fn should_report_ok_when_done(mut action_cmd: Command) {
.stdout("") .stdout("")
.stderr(""); .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 // Because we're talking to a local server, we can verify locally
file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS)); file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS));
} }
@ -98,6 +101,9 @@ fn should_support_json_output(mut action_cmd: Command) {
res.payload[0] 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 // Because we're talking to a local server, we can verify locally
file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS)); file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS));
} }

@ -41,6 +41,9 @@ fn should_report_ok_when_done(mut action_cmd: Command) {
.stdout("") .stdout("")
.stderr(""); .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 // Because we're talking to a local server, we can verify locally
file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS)); file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS));
} }
@ -98,6 +101,9 @@ fn should_support_json_output(mut action_cmd: Command) {
res.payload[0] 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 // Because we're talking to a local server, we can verify locally
file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS)); file.assert(format!("{}{}", FILE_CONTENTS, APPENDED_FILE_CONTENTS));
} }

@ -30,6 +30,9 @@ fn should_report_ok_when_done(mut action_cmd: Command) {
.stdout("") .stdout("")
.stderr(""); .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 // Because we're talking to a local server, we can verify locally
file.assert(FILE_CONTENTS); file.assert(FILE_CONTENTS);
} }
@ -81,6 +84,9 @@ fn should_support_json_output(mut action_cmd: Command) {
res.payload[0] 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 // Because we're talking to a local server, we can verify locally
file.assert(FILE_CONTENTS); file.assert(FILE_CONTENTS);
} }

@ -35,6 +35,9 @@ fn should_report_ok_when_done(mut action_cmd: Command) {
.stdout("") .stdout("")
.stderr(""); .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 // Because we're talking to a local server, we can verify locally
file.assert(FILE_CONTENTS); file.assert(FILE_CONTENTS);
} }
@ -91,6 +94,9 @@ fn should_support_json_output(mut action_cmd: Command) {
res.payload[0] 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 // Because we're talking to a local server, we can verify locally
file.assert(FILE_CONTENTS); file.assert(FILE_CONTENTS);
} }

Loading…
Cancel
Save