Skip to content

Explicitly share a single connection in tests #1610

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

Merged
merged 2 commits into from
Feb 1, 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
188 changes: 185 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ scheduled-thread-pool = "0.2.0"
derive_deref = "1.0.0"
reqwest = "0.9.1"
tempdir = "0.3.7"
parking_lot = "0.7.1"

lettre = {git = "https://github.com/lettre/lettre", version = "0.9"}
lettre_email = {git = "https://github.com/lettre/lettre", version = "0.9"}
Expand Down
3 changes: 2 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl App {
let db_connection_timeout = match (env::var("DB_TIMEOUT"), config.env) {
(Ok(num), _) => num.parse().expect("couldn't parse DB_TIMEOUT"),
(_, Env::Production) => 10,
(_, Env::Test) => 1,
_ => 30,
};

Expand All @@ -88,7 +89,7 @@ impl App {
let repo = git2::Repository::open(&config.git_repo_checkout).unwrap();

App {
diesel_database: db::diesel_pool(&config.db_url, diesel_db_config),
diesel_database: db::diesel_pool(&config.db_url, config.env, diesel_db_config),
github,
session_key: config.session_key.clone(),
git_repo: Mutex::new(repo),
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/crate_owner_invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ struct OwnerInvitation {

/// Handles the `PUT /me/crate_owner_invitations/:crate_id` route.
pub fn handle_invite(req: &mut dyn Request) -> CargoResult<Response> {
let conn = &*req.db_conn()?;

let mut body = String::new();
req.body().read_to_string(&mut body)?;

let conn = &*req.db_conn()?;

let crate_invite: OwnerInvitation =
serde_json::from_str(&body).map_err(|_| human("invalid json request"))?;

Expand All @@ -50,7 +50,7 @@ pub fn handle_invite(req: &mut dyn Request) -> CargoResult<Response> {
}

fn accept_invite(
req: &mut dyn Request,
req: &dyn Request,
conn: &PgConnection,
crate_invite: InvitationResponse,
) -> CargoResult<Response> {
Expand Down Expand Up @@ -88,7 +88,7 @@ fn accept_invite(
}

fn decline_invite(
req: &mut dyn Request,
req: &dyn Request,
conn: &PgConnection,
crate_invite: InvitationResponse,
) -> CargoResult<Response> {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
let categories = new_crate.categories.as_ref().map(|s| &s[..]).unwrap_or(&[]);
let categories: Vec<_> = categories.iter().map(|k| &***k).collect();

let conn = req.db_conn()?;
let conn = app.diesel_database.get()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few hundred lines down we need &mut req, so we need to separate the connection from the request (app was already cloned in this function for other places that have similar problems)


let mut other_warnings = vec![];
if !user.has_verified_email(&conn)? {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn search(req: &mut dyn Request) -> CargoResult<Response> {

let badges = CrateBadge::belonging_to(&crates)
.select((badges::crate_id, badges::all_columns))
.load::<CrateBadge>(&conn)?
.load::<CrateBadge>(&*conn)?
.grouped_by(&crates)
.into_iter()
.map(|badges| badges.into_iter().map(|cb| cb.badge).collect());
Expand Down
Loading