Struct gotham::plain::test::AsyncTestServer [−][src]
pub struct AsyncTestServer { /* fields omitted */ }
Expand description
An AsyncTestServer
, that can be used for testing requests against a server in asynchronous contexts.
The AsyncTestServer
runs in the runtime where it is created and an AsyncTestClient
can be
created to make asynchronous requests to it.
This differs from crate::plain::test::TestServer
in that it doesn’t come with it’s own runtime and therefore
doesn’t crash when used inside of another runtime.
Example
use gotham::plain::test::AsyncTestServer;
let test_server = AsyncTestServer::new(|| Ok(my_handler)).await.unwrap();
let response = test_server.client().get("http://localhost/").perform().await.unwrap();
assert_eq!(response.status(), StatusCode::ACCEPTED);
Implementations
Creates an AsyncTestServer
instance for the crate::handler::Handler
spawned by new_handler
. This server has
the same guarantee given by hyper::server::Server::bind
, that a new service will be spawned
for each connection.
Requests will time out after 10 seconds by default. Use [AsyncTestServer::with_timeout
] for a different timeout.
pub async fn new_with_timeout<NH: NewHandler + 'static>(
new_handler: NH,
timeout: Duration
) -> Result<AsyncTestServer>
pub async fn new_with_timeout<NH: NewHandler + 'static>(
new_handler: NH,
timeout: Duration
) -> Result<AsyncTestServer>
Sets the request timeout to timeout
seconds and returns a new AsyncTestServer
.
Returns a client connected to the AsyncTestServer
. It can be used to make requests against the test server.
The transport is handled internally.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for AsyncTestServer
impl Send for AsyncTestServer
impl Sync for AsyncTestServer
impl Unpin for AsyncTestServer
impl !UnwindSafe for AsyncTestServer
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more