Skip to content

Commit 57a31b7

Browse files
committed
Refactor pool tests
Also actually build + compile types tests <_<
1 parent 10bf6c2 commit 57a31b7

2 files changed

Lines changed: 36 additions & 31 deletions

File tree

src/test/pool.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use std::comm;
2+
use std::sync::Future;
3+
4+
use postgres::NoSsl;
5+
use postgres::pool::PostgresConnectionPool;
6+
7+
#[test]
8+
// Make sure we can take both connections at once and can still get one after
9+
fn test_pool() {
10+
let pool = or_fail!(PostgresConnectionPool::new("postgres://postgres@localhost",
11+
NoSsl, 2));
12+
13+
let (s1, r1) = comm::channel();
14+
let (s2, r2) = comm::channel();
15+
16+
let pool1 = pool.clone();
17+
let mut fut1 = Future::spawn(proc() {
18+
let _conn = pool1.get_connection();
19+
s1.send(());
20+
r2.recv();
21+
});
22+
23+
let pool2 = pool.clone();
24+
let mut fut2 = Future::spawn(proc() {
25+
let _conn = pool2.get_connection();
26+
s2.send(());
27+
r1.recv();
28+
});
29+
30+
fut1.get();
31+
fut2.get();
32+
33+
pool.get_connection();
34+
}

src/test/test.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ extern crate uuid;
99
extern crate openssl;
1010

1111
use serialize::json;
12-
use std::comm;
13-
use std::sync::Future;
1412
use time::Timespec;
1513
use uuid::Uuid;
1614
use openssl::ssl::{SslContext, Sslv3};
@@ -45,7 +43,6 @@ use postgres::error::{PgConnectDbError,
4543
use postgres::types::{ToSql, FromSql, PgInt4, PgVarchar};
4644
use postgres::types::array::{ArrayBase};
4745
use postgres::types::range::{Range, Inclusive, Exclusive, RangeBound};
48-
use postgres::pool::PostgresConnectionPool;
4946

5047
macro_rules! or_fail(
5148
($e:expr) => (
@@ -56,34 +53,8 @@ macro_rules! or_fail(
5653
)
5754
)
5855

59-
#[test]
60-
// Make sure we can take both connections at once and can still get one after
61-
fn test_pool() {
62-
let pool = or_fail!(PostgresConnectionPool::new("postgres://postgres@localhost",
63-
NoSsl, 2));
64-
65-
let (s1, r1) = comm::channel();
66-
let (s2, r2) = comm::channel();
67-
68-
let pool1 = pool.clone();
69-
let mut fut1 = Future::spawn(proc() {
70-
let _conn = pool1.get_connection();
71-
s1.send(());
72-
r2.recv();
73-
});
74-
75-
let pool2 = pool.clone();
76-
let mut fut2 = Future::spawn(proc() {
77-
let _conn = pool2.get_connection();
78-
s2.send(());
79-
r1.recv();
80-
});
81-
82-
fut1.get();
83-
fut2.get();
84-
85-
pool.get_connection();
86-
}
56+
mod types;
57+
mod pool;
8758

8859
#[test]
8960
fn test_non_default_database() {

0 commit comments

Comments
 (0)