-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepro.rs
44 lines (42 loc) · 1.43 KB
/
repro.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use rand::{thread_rng, Rng};
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
use std::time::Duration;
#[tokio::test(flavor = "multi_thread", worker_threads = 10)]
async fn repro_issue() {
let mut pool_options = PgPoolOptions::new()
.max_connections(20)
.acquire_timeout(Duration::from_secs(1));
/*.before_acquire(move |_conn, metadata| {
Box::pin(async move {
Ok(thread_rng().gen_range(1..10) != 1)
})
});*/
/*.after_connect(move |conn, _meta| {
Box::pin(async move {
tokio::time::sleep(Duration::from_millis(500)).await;
Ok(())
})
});*/
let pool = pool_options
.connect("postgres://postgres:postgres@localhost/")
.await
.unwrap();
for _ in 0..1000 {
let pool = pool.clone();
tokio::spawn(async move {
loop {
let res = sqlx::query("SELECT pg_sleep(0.25)").fetch_all(&pool).await;
println!(
"{} max {} size {} idle {}",
res.is_err(),
pool.options().get_max_connections(),
pool.size(),
pool.num_idle(),
);
let sleep = thread_rng().gen_range(1..100);
tokio::time::sleep(tokio::time::Duration::from_millis(sleep)).await;
}
});
}
tokio::time::sleep(tokio::time::Duration::from_secs(600)).await;
}