Struct httptest::ServerPool[][src]

pub struct ServerPool(_, _);
Expand description

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.

Implementations

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.

Get the next available server from the pool.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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