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

feat: show output of failed tests #907

Merged
merged 2 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
axum = { workspace = true, features = ["headers", "json", "query", "ws"] }
bytes = { workspace = true }
cargo = { workspace = true }
cargo_metadata = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
Expand Down
65 changes: 29 additions & 36 deletions deployer/src/deployment/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ use crate::error::{Error, Result, TestError};
use crate::persistence::{DeploymentUpdater, LogLevel, SecretRecorder};
use shuttle_common::storage_manager::{ArtifactsStorageManager, StorageManager};

use cargo::util::interning::InternedString;
use cargo_metadata::Message;
use chrono::Utc;
use crossbeam_channel::Sender;
use opentelemetry::global;
use serde_json::json;
use shuttle_common::claims::Claim;
use shuttle_service::builder::{build_workspace, get_config, BuiltService};
use shuttle_service::builder::{build_workspace, BuiltService};
use tokio::time::{sleep, timeout};
use tracing::{debug, debug_span, error, info, instrument, trace, warn, Instrument, Span};
use tracing_opentelemetry::OpenTelemetrySpanExt;
Expand All @@ -21,13 +20,11 @@ use uuid::Uuid;
use std::collections::{BTreeMap, HashMap};
use std::fmt;
use std::fs::remove_file;
use std::io::Read;
use std::io::{BufRead, BufReader, Read};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::time::Duration;

use cargo::core::compiler::{CompileMode, MessageFormat};
use cargo::core::Workspace;
use cargo::ops::{self, CompileOptions, TestOptions};
use flate2::read::GzDecoder;
use tar::Archive;
use tokio::fs;
Expand Down Expand Up @@ -370,36 +367,32 @@ async fn run_pre_deploy_tests(
}
});

let config = get_config(write)?;
let manifest_path = project_path.join("Cargo.toml");

let ws = Workspace::new(&manifest_path, &config)?;

let mut compile_opts = CompileOptions::new(&config, CompileMode::Test)?;

compile_opts.build_config.message_format = MessageFormat::Json {
render_diagnostics: false,
short: false,
ansi: false,
};

// We set the tests to build with the release profile since deployments compile
// with the release profile by default. This means crates don't need to be
// recompiled in debug mode for the tests, reducing memory usage during deployment.
compile_opts.build_config.requested_profile = InternedString::new("release");

// Build tests with a maximum of 4 workers.
compile_opts.build_config.jobs = 4;

compile_opts.spec = ops::Packages::All;

let opts = TestOptions {
compile_opts,
no_run: false,
no_fail_fast: false,
};
let mut cmd = Command::new("cargo")
.arg("test")
.arg("--release")
.arg("--jobs=4")
.arg("--message-format=json")
.current_dir(project_path)
.stdout(Stdio::piped())
.spawn()
.map_err(TestError::Run)?;

let stdout = cmd.stdout.take().unwrap();
let stdout_reader = BufReader::new(stdout);
stdout_reader
.lines()
.filter_map(|line| line.ok())
.for_each(|line| {
if let Err(error) = write.send(format!("{}\n", line.trim_end_matches('\n'))) {
error!("failed to send line to pipe: {error}");
}
});

ops::run_tests(&ws, &opts, &[]).map_err(TestError::Failed)
if cmd.wait().map_err(TestError::Run)?.success() {
Ok(())
} else {
Err(TestError::Failed)
}
}

/// This will store the path to the executable for each runtime, which will be the users project with
Expand Down Expand Up @@ -541,7 +534,7 @@ ff0e55bda1ff01000000000000000000e0079c01ff12a55500280000",
let failure_project_path = root.join("tests/resources/tests-fail");
assert!(matches!(
super::run_pre_deploy_tests(&failure_project_path, tx.clone()).await,
Err(TestError::Failed(_))
Err(TestError::Failed)
));

let pass_project_path = root.join("tests/resources/tests-pass");
Expand Down
6 changes: 2 additions & 4 deletions deployer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::error::Error as StdError;
use std::io;
use thiserror::Error;

use cargo::util::errors::CliError;

use crate::deployment::gateway_client;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -39,11 +37,11 @@ pub enum Error {
#[derive(Error, Debug)]
pub enum TestError {
#[error("The deployment's tests failed.")]
Failed(CliError),
Failed,
#[error("Failed to setup tests run: {0}")]
Setup(#[from] anyhow::Error),
#[error("Failed to run tests: {0}")]
Run(#[from] tokio::task::JoinError),
Run(#[from] std::io::Error),
}

pub type Result<T> = std::result::Result<T, Error>;