From 247e97b0b9fe24357c2cc321e074a771ffa3a51e Mon Sep 17 00:00:00 2001 From: Anatoly Ikorsky Date: Sat, 5 Feb 2022 14:25:29 +0300 Subject: [PATCH 1/2] ci: Add TiDB tests --- azure-pipelines.yml | 22 ++++++++++++++++++++++ src/conn/pool/mod.rs | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index fe273551..7caca5c3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -195,3 +195,25 @@ jobs: RUST_BACKTRACE: 1 DATABASE_URL: mysql://root:password@127.0.0.1/mysql displayName: Run tests in Docker + + - 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 diff --git a/src/conn/pool/mod.rs b/src/conn/pool/mod.rs index 16888050..c4818f6a 100644 --- a/src/conn/pool/mod.rs +++ b/src/conn/pool/mod.rs @@ -422,6 +422,27 @@ mod test { master.disconnect().await } + #[tokio::test] + async fn should_reuse_connections() -> super::Result<()> { + let constraints = PoolConstraints::new(1, 1).unwrap(); + let opts = get_opts().pool_opts(PoolOpts::default().with_constraints(constraints)); + + let pool = Pool::new(opts); + let mut conn = pool.get_conn().await?; + + let server_version = conn.server_version(); + let connection_id = conn.id(); + + for _ in 0..16 { + drop(conn); + conn = pool.get_conn().await?; + println!("CONN connection_id={}", conn.id()); + assert!(conn.id() == connection_id || server_version < (5, 7, 2)); + } + + Ok(()) + } + #[tokio::test] #[ignore] async fn can_handle_the_pressure() { From b1b0b0ff114f91f0b0a167efa62176106cbd2e2f Mon Sep 17 00:00:00 2001 From: AIkorsky Date: Sat, 5 Feb 2022 15:13:43 +0300 Subject: [PATCH 2/2] Respect TiDB's zero (infinite) wait_timeout --- src/conn/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conn/mod.rs b/src/conn/mod.rs index 872a34f4..2a2caf1c 100644 --- a/src/conn/mod.rs +++ b/src/conn/mod.rs @@ -880,7 +880,7 @@ impl Conn { .opts .conn_ttl() .unwrap_or(self.inner.wait_timeout); - self.idling() > ttl + !ttl.is_zero() && self.idling() > ttl } /// Returns duration since last IO.