Struct TestServerConfig

Source
pub struct TestServerConfig {
    pub api_client: Option<ApiClientBuilder>,
    pub min_backoff_delay: Duration,
    pub max_backoff_delay: Duration,
    pub backoff_jitter: bool,
    pub max_retry_attempts: usize,
}
Expand description

Configuration for test server behavior and client setup.

This struct allows customizing how the TestClient interacts with the test server, including the ApiClient configuration and exponential backoff timing for health checks.

§Fields

  • api_client - Optional pre-configured ApiClient builder for custom client setup
  • min_backoff_delay - Minimum delay for exponential backoff between health check retries
  • max_backoff_delay - Maximum delay for exponential backoff between health check retries
  • backoff_jitter - Whether to add jitter to exponential backoff delays
  • max_retry_attempts - Maximum number of health check retry attempts

§Examples

§Default Configuration

use clawspec_core::test_client::TestServerConfig;
use std::time::Duration;

let config = TestServerConfig::default();
assert!(config.api_client.is_none());
assert_eq!(config.min_backoff_delay, Duration::from_millis(10));
assert_eq!(config.max_backoff_delay, Duration::from_secs(1));
assert_eq!(config.backoff_jitter, true);
assert_eq!(config.max_retry_attempts, 10);

§Custom Configuration

use clawspec_core::{test_client::TestServerConfig, ApiClient};
use std::time::Duration;

let config = TestServerConfig {
    api_client: Some(
        ApiClient::builder()
            .with_host("test-server.local")
            .with_port(3000)
            .with_base_path("/api/v1").unwrap()
    ),
    min_backoff_delay: Duration::from_millis(50),
    max_backoff_delay: Duration::from_secs(5),
    backoff_jitter: false,
    max_retry_attempts: 3,
};

§Using with TestServer

use clawspec_core::test_client::{TestServer, TestServerConfig};
use std::{net::TcpListener, time::Duration};

#[derive(Debug)]
struct MyTestServer;

impl TestServer for MyTestServer {
    type Error = std::io::Error;

    async fn launch(&self, listener: TcpListener) -> Result<(), Self::Error> {
        // Server implementation
        listener.set_nonblocking(true)?;
        let _tokio_listener = tokio::net::TcpListener::from_std(listener)?;
        Ok(())
    }

    fn config(&self) -> TestServerConfig {
        TestServerConfig {
            api_client: Some(
                clawspec_core::ApiClient::builder()
                    .with_host("localhost")
                    .with_base_path("/api").unwrap()
            ),
            min_backoff_delay: Duration::from_millis(25),
            max_backoff_delay: Duration::from_secs(2),
            backoff_jitter: true,
            max_retry_attempts: 15,
        }
    }
}

Fields§

§api_client: Option<ApiClientBuilder>

Optional pre-configured ApiClient builder.

If provided, this builder will be used as the base for creating the ApiClient. If None, a default builder will be used. The TestClient will automatically configure the port based on the bound server address.

§Example

use clawspec_core::{test_client::TestServerConfig, ApiClient};

let config = TestServerConfig {
    api_client: Some(
        ApiClient::builder()
            .with_host("api.example.com")
            .with_base_path("/v1").unwrap()
    ),
    min_backoff_delay: std::time::Duration::from_millis(10),
    max_backoff_delay: std::time::Duration::from_secs(1),
    backoff_jitter: true,
    max_retry_attempts: 10,
};
§min_backoff_delay: Duration

Minimum delay for exponential backoff between health check retries.

This is the initial delay used when the server is unhealthy and needs to be retried. The delay will increase exponentially up to max_backoff_delay.

§Default

10 milliseconds

§Example

use clawspec_core::test_client::TestServerConfig;
use std::time::Duration;

let config = TestServerConfig {
    min_backoff_delay: Duration::from_millis(50), // Start with 50ms
    ..Default::default()
};
§max_backoff_delay: Duration

Maximum delay for exponential backoff between health check retries.

This is the upper bound for the exponential backoff delay. Once the delay reaches this value, it will not increase further.

§Default

1 second

§Example

use clawspec_core::test_client::TestServerConfig;
use std::time::Duration;

let config = TestServerConfig {
    max_backoff_delay: Duration::from_secs(5), // Max 5 seconds
    ..Default::default()
};
§backoff_jitter: bool

Whether to add jitter to the exponential backoff delays.

Jitter adds randomization to retry delays to prevent the “thundering herd” problem when multiple clients retry simultaneously. This is generally recommended for production use.

§Default

true (jitter enabled)

§Example

use clawspec_core::test_client::TestServerConfig;

let config = TestServerConfig {
    backoff_jitter: false, // Disable jitter for predictable timing
    ..Default::default()
};
§max_retry_attempts: usize

Maximum number of health check retry attempts.

This limits the total number of health check attempts before giving up. The health check will stop retrying once this number of attempts is reached, preventing infinite loops when a server never becomes healthy.

§Default

10 attempts

§Example

use clawspec_core::test_client::TestServerConfig;

let config = TestServerConfig {
    max_retry_attempts: 5, // Only try 5 times before giving up
    ..Default::default()
};

Trait Implementations§

Source§

impl Clone for TestServerConfig

Source§

fn clone(&self) -> TestServerConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TestServerConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TestServerConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,