#![allow(dead_code)]
use std::future::Future;
use std::net::SocketAddr;
use brain_db_sdk::verbs::{EncodeBuilder, ForgetBuilder, RecallBuilder};
use brain_db_sdk::{Auth, BrainClient, BrainError, BrainHttpClient, ClientConfig};
const fn assert_send<T: Send>(_: &T) {}
const fn assert_send_sync<T: Send + Sync>() {}
#[test]
fn the_clients_and_their_config_are_send_and_sync() {
assert_send_sync::<BrainClient>();
assert_send_sync::<BrainHttpClient>();
assert_send_sync::<ClientConfig>();
assert_send_sync::<Auth>();
assert_send_sync::<BrainError>();
}
fn _wire_verb_futures_are_send(client: &BrainClient) {
assert_send(&client.encode(&EncodeBuilder::new("").build()));
assert_send(&client.recall(&RecallBuilder::new("").build()));
assert_send(&client.forget(&ForgetBuilder::new(0).build()));
}
fn _the_close_future_is_send(client: BrainClient) {
assert_send(&client.close());
}
fn _http_verb_futures_are_send(client: &BrainHttpClient) {
assert_send(&client.whoami());
assert_send(&client.capabilities());
}
fn _connect_futures_are_send() {
let addr = SocketAddr::from(([127, 0, 0, 1], 1));
assert_send(&BrainClient::connect(addr, Auth::Token(Vec::new())));
assert_send(&BrainClient::connect_with(
addr,
ClientConfig::new(Auth::Token(Vec::new())),
));
}
#[test]
fn a_spawned_task_can_own_a_client() {
const fn spawnable<F: Future<Output = ()> + Send + 'static>(_: &F) {}
let task = async {
let addr = SocketAddr::from(([127, 0, 0, 1], 1));
if let Ok(client) = BrainClient::connect(addr, Auth::Token(Vec::new())).await {
let _ = client.close().await;
}
};
spawnable(&task);
}