Unverified Commit 5bb8b357 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Ensure that clients are Send+Sync (#243)

* Ensure that clients are Send+Sync

* Make constructor more ergonomic
parent 7d39bf6b
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -24,13 +24,13 @@ impl Standard {
        Self(Connector::Https(hyper::Client::builder().build::<_, SdkBody>(https)))
    }

    /// A connection based on the provided `Box<dyn HttpService>`
    /// A connection based on the provided `impl HttpService`
    ///
    /// Generally, `https()` should be used instead. This constructor is intended to support
    /// Generally, [`Standard::https()`](Standard::https) should be used. This constructor is intended to support
    /// using things like [`TestConnection`](crate::test_connection::TestConnection) or alternative
    /// http implementations.
    pub fn new(connector: Box<dyn HttpService>) -> Self {
        Self(Connector::Dyn(connector))
    pub fn new(connector: impl HttpService + 'static) -> Self {
        Self(Connector::Dyn(Box::new(connector)))
    }
}

@@ -62,7 +62,7 @@ impl Clone for Box<dyn HttpService> {
    }
}

pub trait HttpService: Send {
pub trait HttpService: Send + Sync {
    /// Return whether this service is ready to accept a request
    ///
    /// See [`Service::poll_ready`](tower::Service::poll_ready)
@@ -90,6 +90,7 @@ impl<S> HttpService for S
where
    S: Service<http::Request<SdkBody>, Response = http::Response<hyper::Body>>
        + Send
        + Sync
        + Clone
        + 'static,
    S::Error: Into<BoxError> + Send + Sync + 'static,
+17 −1
Original line number Diff line number Diff line
@@ -138,13 +138,21 @@ where

#[cfg(test)]
mod tests {
    use crate::Client;
    use crate::{Client, conn};
    use crate::test_connection::TestConnection;

    #[test]
    fn construct_default_client() {
        let _ = Client::https();
    }

    #[test]
    fn construct_test_client() {
        let test_conn = TestConnection::<String>::new(vec![]);
        let client = Client::new(conn::Standard::new(test_conn));
        is_send_sync(client);
    }

    #[test]
    fn client_debug_includes_retry_info() {
        let client = Client::https();
@@ -152,4 +160,12 @@ mod tests {
        assert!(s.contains("RetryConfig"));
        assert!(s.contains("quota_available"));
    }

    fn is_send_sync<T: Send + Sync>(_: T) {}

    #[test]
    fn client_is_send_sync() {
        let c = Client::https();
        is_send_sync(c);
    }
}