Skip to content

Commit

Permalink
ci: Test that pool reuses TiDB connections
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbeam committed Feb 5, 2022
1 parent 027a850 commit 986240a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ jobs:
DATABASE_URL: mysql://root:password@localhost/mysql
displayName: Run tests
- job: "TestTiDB"
pool:
vmImage: "ubuntu-latest"
strategy:
matrix:
v5.3.0:
DB_VERSION: "v5.3.0"
v5.0.6:
DB_VERSION: "v5.0.6"
steps:
- bash: |
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
source ~/.profile
tiup playground $(DB_VERSION) --db 1 --pd 1 --kv 1 &
while ! nc -W 1 localhost 4000 | grep -q -P '.+'; do sleep 1; done
displayName: Install and run TiDB
- bash: cargo test should_reuse_connections -- --nocapture
displayName: Run tests
env:
RUST_BACKTRACE: 1
DATABASE_URL: mysql://root@127.0.0.1:4000/mysql

- job: "TestMySql"
pool:
vmImage: "ubuntu-latest"
Expand Down
5 changes: 5 additions & 0 deletions src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ impl ConnInner {
pub struct Conn(Box<ConnInner>);

impl Conn {
/// Returns version number reported by the server.
pub fn server_version(&self) -> (u16, u16, u16) {
self.0.server_version.unwrap()
}

/// Returns connection identifier.
pub fn connection_id(&self) -> u32 {
self.0.connection_id
Expand Down
18 changes: 18 additions & 0 deletions src/conn/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,24 @@ mod test {
a.add();
}

#[test]
fn should_reuse_connections() -> crate::Result<()> {
let pool = Pool::new_manual(1, 1, get_opts())?;
let mut conn = pool.get_conn()?;

let server_version = conn.server_version();
let connection_id = conn.connection_id();

for _ in 0..16 {
drop(conn);
conn = pool.get_conn()?;
println!("CONN connection_id={}", conn.connection_id());
assert!(conn.connection_id() == connection_id || server_version < (5, 7, 2));
}

Ok(())
}

#[test]
fn should_start_transaction_on_PooledConn() {
let pool = Pool::new(get_opts()).unwrap();
Expand Down

0 comments on commit 986240a

Please sign in to comment.