diff --git a/src/test/pool.rs b/src/test/pool.rs new file mode 100644 index 00000000..a1bf500e --- /dev/null +++ b/src/test/pool.rs @@ -0,0 +1,34 @@ +use std::comm; +use std::sync::Future; + +use postgres::NoSsl; +use postgres::pool::PostgresConnectionPool; + +#[test] +// Make sure we can take both connections at once and can still get one after +fn test_pool() { + let pool = or_fail!(PostgresConnectionPool::new("postgres://postgres@localhost", + NoSsl, 2)); + + let (s1, r1) = comm::channel(); + let (s2, r2) = comm::channel(); + + let pool1 = pool.clone(); + let mut fut1 = Future::spawn(proc() { + let _conn = pool1.get_connection(); + s1.send(()); + r2.recv(); + }); + + let pool2 = pool.clone(); + let mut fut2 = Future::spawn(proc() { + let _conn = pool2.get_connection(); + s2.send(()); + r1.recv(); + }); + + fut1.get(); + fut2.get(); + + pool.get_connection(); +} diff --git a/src/test/test.rs b/src/test/test.rs index c452fa2d..426fe6ca 100644 --- a/src/test/test.rs +++ b/src/test/test.rs @@ -9,8 +9,6 @@ extern crate uuid; extern crate openssl; use serialize::json; -use std::comm; -use std::sync::Future; use time::Timespec; use uuid::Uuid; use openssl::ssl::{SslContext, Sslv3}; @@ -45,7 +43,6 @@ use postgres::error::{PgConnectDbError, use postgres::types::{ToSql, FromSql, PgInt4, PgVarchar}; use postgres::types::array::{ArrayBase}; use postgres::types::range::{Range, Inclusive, Exclusive, RangeBound}; -use postgres::pool::PostgresConnectionPool; macro_rules! or_fail( ($e:expr) => ( @@ -56,34 +53,8 @@ macro_rules! or_fail( ) ) -#[test] -// Make sure we can take both connections at once and can still get one after -fn test_pool() { - let pool = or_fail!(PostgresConnectionPool::new("postgres://postgres@localhost", - NoSsl, 2)); - - let (s1, r1) = comm::channel(); - let (s2, r2) = comm::channel(); - - let pool1 = pool.clone(); - let mut fut1 = Future::spawn(proc() { - let _conn = pool1.get_connection(); - s1.send(()); - r2.recv(); - }); - - let pool2 = pool.clone(); - let mut fut2 = Future::spawn(proc() { - let _conn = pool2.get_connection(); - s2.send(()); - r1.recv(); - }); - - fut1.get(); - fut2.get(); - - pool.get_connection(); -} +mod types; +mod pool; #[test] fn test_non_default_database() {