|
| 1 | +use std::time::Duration; |
| 2 | + |
| 3 | +use bson::doc; |
1 | 4 | use tokio::sync::RwLockWriteGuard;
|
2 | 5 |
|
3 |
| -use crate::test::{run_spec_test, run_v2_test, LOCK}; |
| 6 | +use crate::{ |
| 7 | + test::{ |
| 8 | + run_spec_test, |
| 9 | + run_v2_test, |
| 10 | + FailCommandOptions, |
| 11 | + FailPoint, |
| 12 | + FailPointMode, |
| 13 | + TestClient, |
| 14 | + CLIENT_OPTIONS, |
| 15 | + LOCK, |
| 16 | + }, |
| 17 | + RUNTIME, |
| 18 | +}; |
4 | 19 |
|
5 | 20 | #[cfg_attr(feature = "tokio-runtime", tokio::test(threaded_scheduler))]
|
6 | 21 | #[cfg_attr(feature = "async-std-runtime", async_std::test)]
|
7 | 22 | async fn run() {
|
8 | 23 | let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
|
9 | 24 | run_spec_test(&["retryable-reads"], run_v2_test).await;
|
10 | 25 | }
|
| 26 | + |
| 27 | +/// Test ensures that the connection used in the first attempt of a retry is released back into the |
| 28 | +/// pool before the second attempt. |
| 29 | +#[cfg_attr(feature = "tokio-runtime", tokio::test(threaded_scheduler))] |
| 30 | +#[cfg_attr(feature = "async-std-runtime", async_std::test)] |
| 31 | +async fn retry_releases_connection() { |
| 32 | + let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await; |
| 33 | + |
| 34 | + let mut client_options = CLIENT_OPTIONS.clone(); |
| 35 | + client_options.hosts.drain(1..); |
| 36 | + client_options.retry_reads = Some(true); |
| 37 | + client_options.max_pool_size = Some(1); |
| 38 | + |
| 39 | + let client = TestClient::with_options(Some(client_options), true).await; |
| 40 | + if !client.supports_fail_command().await { |
| 41 | + println!("skipping retry_releases_connection due to failCommand not being supported"); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + let collection = client |
| 46 | + .database("retry_releases_connection") |
| 47 | + .collection("retry_releases_connection"); |
| 48 | + collection.insert_one(doc! { "x": 1 }, None).await.unwrap(); |
| 49 | + |
| 50 | + let options = FailCommandOptions::builder().error_code(91).build(); |
| 51 | + let failpoint = FailPoint::fail_command(&["find"], FailPointMode::Times(1), Some(options)); |
| 52 | + let _fp_guard = client.enable_failpoint(failpoint, None).await.unwrap(); |
| 53 | + |
| 54 | + RUNTIME |
| 55 | + .timeout(Duration::from_secs(1), collection.find_one(doc! {}, None)) |
| 56 | + .await |
| 57 | + .expect("operation should not time out") |
| 58 | + .expect("find should succeed"); |
| 59 | +} |
0 commit comments