From 6e92a7d93d85beb5ed4d67268db6db3a667cdb23 Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:46:46 -0600 Subject: [PATCH] Bugfix/output timeout (#2471) * Fix: Test with the buf reader never finishing * fix NoOutput deserialization --------- Co-authored-by: J H <2364004+Blu-J@users.noreply.github.com> --- backend/src/procedure/docker.rs | 23 ++++++++++++++--------- backend/src/procedure/mod.rs | 8 +++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/backend/src/procedure/docker.rs b/backend/src/procedure/docker.rs index 463b2f2e4..3f72993a0 100644 --- a/backend/src/procedure/docker.rs +++ b/backend/src/procedure/docker.rs @@ -396,7 +396,7 @@ impl DockerProcedure { cmd.arg("exec"); - cmd.args(self.docker_args_inject(pkg_id).await?); + cmd.args(self.docker_args_inject(pkg_id)); let input_buf = if let (Some(input), Some(format)) = (&input, &self.io_format) { cmd.stdin(std::process::Stdio::piped()); Some(format.to_vec(input)?) @@ -756,7 +756,7 @@ impl DockerProcedure { + self.args.len(), // [ARG...] ) } - async fn docker_args_inject(&self, pkg_id: &PackageId) -> Result>, Error> { + fn docker_args_inject(&self, pkg_id: &PackageId) -> Vec> { let mut res = self.new_docker_args(); if let Some(shm_size_mb) = self.shm_size_mb { res.push(OsStr::new("--shm-size").into()); @@ -769,7 +769,7 @@ impl DockerProcedure { res.extend(self.args.iter().map(|s| OsStr::new(s).into())); - Ok(res) + res } } @@ -893,13 +893,11 @@ async fn buf_reader_to_lines( limit: impl Into>, ) -> Result, Error> { let mut lines = reader.lines(); - let mut output = RingVec::new(limit.into().unwrap_or(1000)); - while let Ok(line) = lines.next_line().await { - if let Some(line) = line { - output.push(line); - } + let mut answer = RingVec::new(limit.into().unwrap_or(1000)); + while let Some(line) = lines.next_line().await? { + answer.push(line); } - let output: Vec = output.value.into_iter().collect(); + let output: Vec = answer.value.into_iter().collect(); Ok(output) } @@ -964,4 +962,11 @@ mod tests { assert_eq!(CAPACITY_IN, ring.value.capacity()); assert_eq!(CAPACITY_IN, ring.value.len()); } + + #[test] + fn tests_buf_reader_to_lines() { + let mut reader = BufReader::new("hello\nworld\n".as_bytes()); + let lines = futures::executor::block_on(buf_reader_to_lines(&mut reader, None)).unwrap(); + assert_eq!(lines, vec!["hello", "world"]); + } } diff --git a/backend/src/procedure/mod.rs b/backend/src/procedure/mod.rs index d6d01bf00..62f4de9cf 100644 --- a/backend/src/procedure/mod.rs +++ b/backend/src/procedure/mod.rs @@ -171,7 +171,13 @@ impl<'de> Deserialize<'de> for NoOutput { where D: serde::Deserializer<'de>, { - let _ = Value::deserialize(deserializer)?; + let _ = Value::deserialize(deserializer); Ok(NoOutput) } } + +#[test] +fn test_deser_no_output() { + serde_json::from_str::("").unwrap(); + serde_json::from_str::>("{\"Ok\": null}").unwrap(); +}