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

Reduce the number of git clones in the test framework #1686

Merged
merged 5 commits into from
May 22, 2019
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
6 changes: 0 additions & 6 deletions src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub use self::debug::*;
pub use self::ember_index_rewrite::EmberIndexRewrite;
pub use self::head::Head;
use self::log_connection_pool_status::LogConnectionPoolStatus;
use self::run_pending_background_jobs::RunPendingBackgroundJobs;
pub use self::security_headers::SecurityHeaders;
pub use self::static_or_continue::StaticOrContinue;

Expand All @@ -24,7 +23,6 @@ mod head;
mod log_connection_pool_status;
mod log_request;
mod require_user_agent;
mod run_pending_background_jobs;
mod security_headers;
mod static_or_continue;

Expand Down Expand Up @@ -102,9 +100,5 @@ pub fn build_middleware(app: Arc<App>, endpoints: R404) -> MiddlewareBuilder {
m.around(log_request::LogRequests::default());
}

if env == Env::Test {
m.add(RunPendingBackgroundJobs);
}

m
}
55 changes: 0 additions & 55 deletions src/middleware/run_pending_background_jobs.rs

This file was deleted.

13 changes: 8 additions & 5 deletions src/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,22 @@ pub struct OkBool {
ok: bool,
}

fn app() -> (
/// Initialize the app and a proxy that can record and playback outgoing HTTP requests
fn app_with_proxy() -> (
record::Bomb,
Arc<App>,
conduit_middleware::MiddlewareBuilder,
) {
let (proxy, bomb) = record::proxy();
let (app, handler) = simple_app(Some(proxy));
let (app, handler) = init_app(Some(proxy));
(bomb, app, handler)
}

fn simple_app(proxy: Option<String>) -> (Arc<App>, conduit_middleware::MiddlewareBuilder) {
git::init();
fn app() -> (Arc<App>, conduit_middleware::MiddlewareBuilder) {
init_app(None)
}

fn init_app(proxy: Option<String>) -> (Arc<App>, conduit_middleware::MiddlewareBuilder) {
let uploader = Uploader::S3 {
bucket: s3::Bucket::new(
String::from("alexcrichton-test"),
Expand Down Expand Up @@ -289,7 +292,7 @@ fn logout(req: &mut dyn Request) {
fn multiple_live_references_to_the_same_connection_can_be_checked_out() {
use std::ptr;

let (_bomb, app, _) = app();
let (app, _) = app();
let conn1 = app.diesel_database.get().unwrap();
let conn2 = app.diesel_database.get().unwrap();
let conn1_ref: &PgConnection = &conn1;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn show() {
#[test]
#[allow(clippy::cyclomatic_complexity)]
fn update_crate() {
let (_b, app, middle) = app();
let (app, middle) = app();
let mut req = req(Method::Get, "/api/v1/categories/foo");
macro_rules! cnt {
($req:expr, $cat:expr) => {{
Expand Down
39 changes: 7 additions & 32 deletions src/tests/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use std::path::PathBuf;
use std::sync::Once;
use std::thread;

use url::Url;

fn root() -> PathBuf {
env::current_dir()
.unwrap()
.join("tmp")
.join("tests")
.join(thread::current().name().unwrap())
}

Expand All @@ -29,38 +28,14 @@ pub fn init() {
fs::create_dir_all(root().parent().unwrap()).unwrap();
});

// Prepare a bare remote repo
{
let bare = git2::Repository::init_bare(&bare()).unwrap();
let mut config = bare.config().unwrap();
config.set_str("user.name", "name").unwrap();
config.set_str("user.email", "email").unwrap();
}

// Initialize a fresh checkout
let checkout = git2::Repository::init(&checkout()).unwrap();
let url = Url::from_file_path(&*bare()).ok().unwrap().to_string();

// Setup the `origin` remote
checkout.remote_set_url("origin", &url).unwrap();
checkout.remote_set_pushurl("origin", Some(&url)).unwrap();
checkout
.remote_add_push("origin", "refs/heads/master")
.unwrap();

// Create an empty initial commit
let mut config = checkout.config().unwrap();
let bare = git2::Repository::init_bare(&bare()).unwrap();
let mut config = bare.config().unwrap();
config.set_str("user.name", "name").unwrap();
config.set_str("user.email", "email").unwrap();
let mut index = checkout.index().unwrap();
let mut index = bare.index().unwrap();
let id = index.write_tree().unwrap();
let tree = checkout.find_tree(id).unwrap();
let sig = checkout.signature().unwrap();
checkout
.commit(Some("HEAD"), &sig, &sig, "Initial Commit", &tree, &[])
let tree = bare.find_tree(id).unwrap();
let sig = bare.signature().unwrap();
bare.commit(Some("HEAD"), &sig, &sig, "Initial Commit", &tree, &[])
.unwrap();

// Push the commit to the remote repo
let mut origin = checkout.find_remote("origin").unwrap();
origin.push(&["refs/heads/master"], None).unwrap();
}
Loading