Skip to content

Commit 7f30e24

Browse files
authored
docs(client): explained how Client::clone works and added 2 tests (#284)
1 parent acf23c5 commit 7f30e24

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ mod rowbinary;
3737
mod ticks;
3838

3939
/// A client containing HTTP pool.
40+
///
41+
/// ### Cloning behavior
42+
/// Clones share the same HTTP transport but store their own configurations.
43+
/// Any `with_*` configuration method (e.g., [`Client::with_option`]) applies
44+
/// only to future clones, because [`Client::clone`] creates a deep copy
45+
/// of the [`Client`] configuration, except the transport.
4046
#[derive(Clone)]
4147
pub struct Client {
4248
http: Arc<dyn HttpClient>,
@@ -518,4 +524,18 @@ mod client_tests {
518524
let client = client.with_validation(true);
519525
assert!(client.validation);
520526
}
527+
528+
#[test]
529+
fn it_does_follow_previous_configuration() {
530+
let client = Client::default().with_option("async_insert", "1");
531+
assert_eq!(client.options, client.clone().options,);
532+
}
533+
534+
#[test]
535+
fn it_does_not_follow_future_configuration() {
536+
let client = Client::default();
537+
let client_clone = client.clone();
538+
let client = client.with_option("async_insert", "1");
539+
assert_ne!(client.options, client_clone.options,);
540+
}
521541
}

0 commit comments

Comments
 (0)