[][src]Struct httptest::ServerPool

pub struct ServerPool(_, _);

A pool of shared servers.

The typical way to use this library is to create a new Server for each test using Server::run. This way each test contains it's own independent state. However for very large test suites it may be beneficial to share servers between test runs. This is typically only desirable when running into limits because the test framework spins up an independent thread for each test and system wide resources (TCP ports) may become scarce. In those cases you can opt into using a shared ServerPool that will create a maximum of N servers that tests can share. Invoking get_server on the pool will return a ServerHandle that deref's to a Server. For the life of the ServerHandle it has unique access to this server instance. When the handle is dropped the server expectations are asserted and cleared and the server is returned back into the ServerPool for use by another test.

Example:

// Create a server pool that will create at most 99 servers.
static SERVER_POOL: ServerPool = ServerPool::new(99);

#[test]
fn test_one() {
    let server = SERVER_POOL.get_server();
    server.expect(Expectation::matching(any()).respond_with(status_code(200)));
    // invoke http requests to server.
     
    // server will assert expectations are met on drop.
}

#[test]
fn test_two() {
    let server = SERVER_POOL.get_server();
    server.expect(Expectation::matching(any()).respond_with(status_code(200)));
    // invoke http requests to server.
     
    // server will assert expectations are met on drop.
}

A pool of running servers.

Methods

impl ServerPool[src]

pub const fn new(max_servers: usize) -> Self[src]

Create a new pool of servers.

max_servers is the maximum number of servers that will be created. servers are created on-demand when get_server is invoked.

pub fn get_server(&self) -> ServerHandle[src]

Get the next available server from the pool.

Trait Implementations

impl Debug for ServerPool[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.