Repository navigation
If I pause tokio's clock, acquiring a connection from the pool always times out. How can I best work around this? #4459
|
Tokio has the
This is very useful in tests; suppose I have some logic which writes a row to the DB, waits five minutes, and then performs another action. I don't want my tests to actually spend five minutes sleeping, but due to the auto-advance feature, they can just skip ahead. Only problem is, pausing the clock seems to make acquiring the connection from the pool always time out, even when there are idle connections in the pool. tokio::time::pause();
println!("size: {}, idle: {}", test_db.db_pool.size(), test_db.db_pool.num_idle());
let mut conn = assert_ok!(test_db.db_pool.acquire().await);Setting the acquire_timeout to 24 hours does seem to work around it, but is there a better way to do it? |
Replies: 2 comments 1 reply
This comment was marked as spam.
This comment was marked as spam.
|
What times out isn't waiting for a free connection: you have 3 idle ones. It's the health check sqlx runs on an idle connection before handing it out ( For tests with a paused clock, turn the check off on the test pool: let pool = PgPoolOptions::new()
.test_before_acquire(false)
// ...
.connect(&url)
.await?;I reproduced it with sqlx 0.8.6 (SQLite in-memory, 3 idle connections, One related thing, which I didn't reproduce: since the paused clock can jump far ahead, the pool's own |
What times out isn't waiting for a free connection: you have 3 idle ones. It's the health check sqlx runs on an idle connection before handing it out (
test_before_acquire, on by default). That check does I/O, so while it's in flight the runtime has nothing else to do, and with a paused clock tokio auto-advances straight to the next timer, which is the acquire timeout. That's also why a 24 hacquire_timeout"fixes" it: it's no longer the next timer.For tests with a paused clock, turn the check off on the test pool:
I reproduced it with sqlx 0.8.6 (SQLite in-memory, 3 idle connections,
…