Skip to content

Commit

Permalink
[nextest-runner] add more information to errors returned by run_test_…
Browse files Browse the repository at this point in the history
…inner
  • Loading branch information
sunshowers committed Sep 25, 2023
1 parent 2622505 commit b673fa3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
29 changes: 29 additions & 0 deletions nextest-runner/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,35 @@ impl ConfigParseOverrideError {
}
}

/// An execution error was returned while running a test.
///
/// Internal error type.
#[derive(Debug, Error)]
#[non_exhaustive]
pub(crate) enum RunTestError {
#[error("error spawning test process")]
Spawn(#[source] std::io::Error),

#[error("error waiting for setup script to exit")]
Wait(#[source] std::io::Error),

#[error("error collecting test output")]
CollectOutput(#[from] CollectTestOutputError),
}

/// An error was returned while collecting test output.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CollectTestOutputError {
/// An error occurred while reading standard output.
#[error("error reading standard output")]
ReadStdout(#[source] std::io::Error),

/// An error occurred while reading standard error.
#[error("error reading standard error")]
ReadStderr(#[source] std::io::Error),
}

/// An unknown test group was specified in the config.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
Expand Down
20 changes: 13 additions & 7 deletions nextest-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use crate::{
config::{NextestProfile, RetryPolicy, TestGroup, TestSettings, TestThreads},
double_spawn::DoubleSpawnInfo,
errors::{ConfigureHandleInheritanceError, TestRunnerBuildError},
errors::{
CollectTestOutputError, ConfigureHandleInheritanceError, RunTestError, TestRunnerBuildError,
},
list::{TestExecuteContext, TestInstance, TestList},
reporter::{
CancelReason, FinalStatusLevel, StatusLevel, TestEvent, TestEventKind, TestOutputDisplay,
Expand Down Expand Up @@ -657,7 +659,7 @@ impl<'a> TestRunnerInner<'a> {
run_sender: &UnboundedSender<InternalTestEvent<'a>>,
forward_receiver: &mut tokio::sync::broadcast::Receiver<SignalForwardEvent>,
delay_before_start: Duration,
) -> std::io::Result<InternalExecuteStatus> {
) -> Result<InternalExecuteStatus, RunTestError> {
let ctx = TestExecuteContext {
double_spawn: &self.double_spawn,
target_runner: &self.target_runner,
Expand All @@ -682,7 +684,7 @@ impl<'a> TestRunnerInner<'a> {
.stderr(std::process::Stdio::piped());
};

let mut child = cmd.spawn()?;
let mut child = cmd.spawn().map_err(RunTestError::Spawn)?;

// If assigning the child to the job fails, ignore this. This can happen if the process has
// exited.
Expand Down Expand Up @@ -821,7 +823,7 @@ impl<'a> TestRunnerInner<'a> {
(res, leaked)
};

let output = res?;
let output = res.map_err(RunTestError::Wait)?;
let exit_status = output;

let status = status.unwrap_or_else(|| {
Expand Down Expand Up @@ -869,19 +871,23 @@ fn collect_output<'a>(
stdout: &'a mut BytesMut,
child_stderr: Option<tokio::process::ChildStderr>,
stderr: &'a mut BytesMut,
) -> impl Future<Output = Result<(), std::io::Error>> + 'a {
) -> impl Future<Output = Result<(), CollectTestOutputError>> + 'a {
// Set up futures for reading from stdout and stderr.
let stdout_fut = async {
if let Some(mut child_stdout) = child_stdout {
read_all_to_bytes(stdout, &mut child_stdout).await
read_all_to_bytes(stdout, &mut child_stdout)
.await
.map_err(CollectTestOutputError::ReadStdout)
} else {
Ok(())
}
};

let stderr_fut = async {
if let Some(mut child_stderr) = child_stderr {
read_all_to_bytes(stderr, &mut child_stderr).await
read_all_to_bytes(stderr, &mut child_stderr)
.await
.map_err(CollectTestOutputError::ReadStderr)
} else {
Ok(())
}
Expand Down

0 comments on commit b673fa3

Please sign in to comment.