liminal-server 0.25.4

Standalone server for the liminal messaging bus
Documentation
use super::{
    Arc, AtomTable, CONNECTION_READY_ATOM, CONNECTION_SHUTDOWN_CONTROL_ATOM, ConnectionNotifier,
    ConnectionRuntime, ConnectionRuntimeInstallation, ConnectionServiceInstallation,
    ConnectionServices, LimitsConfig, PassVerifier, Weak,
};

impl ConnectionRuntime {
    /// Builds a runtime wrapping `services` for unit tests that exercise
    /// `apply_frame` without a live scheduler. Uses a fresh interned control atom
    /// and no notifier.
    #[cfg(test)]
    pub(in crate::server::connection) fn for_tests(services: Arc<dyn ConnectionServices>) -> Self {
        let atoms = AtomTable::with_common_atoms();
        let control_atom = atoms.intern(CONNECTION_SHUTDOWN_CONTROL_ATOM);
        let ready_atom = atoms.intern(CONNECTION_READY_ATOM);
        Self::new(
            ConnectionRuntimeInstallation {
                services: ConnectionServiceInstallation::capture(services),
                incarnations: None,
                fatal_shutdown: None,
            },
            control_atom,
            ready_atom,
            Weak::new(),
            None,
            (None, None),
            LimitsConfig::default(),
        )
    }

    /// Builds a runtime wrapping `services` with explicit `limits` for unit tests
    /// that exercise the ยง5 admission caps without a live scheduler.
    #[cfg(test)]
    pub(in crate::server::connection) fn for_tests_with_limits(
        services: Arc<dyn ConnectionServices>,
        limits: LimitsConfig,
    ) -> Self {
        let atoms = AtomTable::with_common_atoms();
        let control_atom = atoms.intern(CONNECTION_SHUTDOWN_CONTROL_ATOM);
        let ready_atom = atoms.intern(CONNECTION_READY_ATOM);
        Self::new(
            ConnectionRuntimeInstallation {
                services: ConnectionServiceInstallation::capture(services),
                incarnations: None,
                fatal_shutdown: None,
            },
            control_atom,
            ready_atom,
            Weak::new(),
            None,
            (None, None),
            limits,
        )
    }

    /// Builds a runtime wrapping `services` with a configured auth `token` for unit
    /// tests that exercise the `Connect` handshake enforcement without a live
    /// scheduler. Uses a fresh interned control atom and no notifier.
    #[cfg(test)]
    pub(in crate::server::connection) fn for_tests_with_auth_token(
        services: Arc<dyn ConnectionServices>,
        token: Vec<u8>,
    ) -> Self {
        let atoms = AtomTable::with_common_atoms();
        let control_atom = atoms.intern(CONNECTION_SHUTDOWN_CONTROL_ATOM);
        let ready_atom = atoms.intern(CONNECTION_READY_ATOM);
        Self::new(
            ConnectionRuntimeInstallation {
                services: ConnectionServiceInstallation::capture(services),
                incarnations: None,
                fatal_shutdown: None,
            },
            control_atom,
            ready_atom,
            Weak::new(),
            None,
            (Some(token), None),
            LimitsConfig::default(),
        )
    }

    /// Builds a runtime wrapping `services` with a `notifier` for unit tests that
    /// exercise `apply_frame` and the close path without a live scheduler.
    #[cfg(test)]
    pub(in crate::server::connection) fn for_tests_with_notifier(
        services: Arc<dyn ConnectionServices>,
        notifier: Arc<dyn ConnectionNotifier>,
    ) -> Self {
        let atoms = AtomTable::with_common_atoms();
        let control_atom = atoms.intern(CONNECTION_SHUTDOWN_CONTROL_ATOM);
        let ready_atom = atoms.intern(CONNECTION_READY_ATOM);
        Self::new(
            ConnectionRuntimeInstallation {
                services: ConnectionServiceInstallation::capture(services),
                incarnations: None,
                fatal_shutdown: None,
            },
            control_atom,
            ready_atom,
            Weak::new(),
            Some(notifier),
            (None, None),
            LimitsConfig::default(),
        )
    }

    /// Builds a runtime wrapping `services` that verifies registry passes
    /// with `verifier`, accepts the bearer `token` when given, and reports to
    /// `notifier`, for unit tests of a worker
    /// bound to the holder its `Connect` verified (ACCESS-004).
    #[cfg(test)]
    pub(in crate::server::connection) fn for_tests_with_pass(
        services: Arc<dyn ConnectionServices>,
        notifier: Arc<dyn ConnectionNotifier>,
        token: Option<Vec<u8>>,
        verifier: PassVerifier,
    ) -> Self {
        let atoms = AtomTable::with_common_atoms();
        let control_atom = atoms.intern(CONNECTION_SHUTDOWN_CONTROL_ATOM);
        let ready_atom = atoms.intern(CONNECTION_READY_ATOM);
        Self::new(
            ConnectionRuntimeInstallation {
                services: ConnectionServiceInstallation::capture(services),
                incarnations: None,
                fatal_shutdown: None,
            },
            control_atom,
            ready_atom,
            Weak::new(),
            Some(notifier),
            (token, Some(verifier)),
            LimitsConfig::default(),
        )
    }
}