Skip to main content

PostgresHarness

Struct PostgresHarness 

Source
pub struct PostgresHarness { /* private fields */ }
Expand description

Process-local owner of a PostgreSQL 18 server and its database capacity.

Implementations§

Source§

impl PostgresHarness

Source

pub async fn start(config: HarnessConfig) -> Result<Self>

Source

pub fn project(&self) -> &ProjectName

Source

pub fn admin_database_url(&self) -> &str

Source

pub fn is_external(&self) -> bool

Source

pub fn container_id(&self) -> Option<&str>

Returns the owned container ID, or None in external-server mode.

Builds without the containers feature always return None.

Source

pub fn connection_limits(&self) -> ConnectionLimits

Returns the resolved downstream connection-permit policy used by this harness’s database admission control.

Source

pub async fn shutdown(&self) -> Result<()>

Closes database admission, drains accepted cleanup, and removes an owned container.

Admission remains closed after the first owned shutdown attempt, even if container removal fails. External servers and their admission remain untouched. Repeated and concurrent calls do not retry removal; the call that completes the terminal worker reports any removal error, while later calls observe completed shutdown. Active leases remain owned but can no longer contact a successfully removed server. Cleanup submissions already accepted by the bounded server queue finish before its pooled admin sessions and container are closed. Deferred failures are returned from this barrier. External-server shutdown remains a no-op, including in builds without the containers feature; call Self::drain_deferred_cleanup explicitly for an external server.

Source

pub async fn drain_deferred_cleanup(&self) -> Result<()>

Waits for every database cleanup accepted before this call.

Failures from DatabaseLease::defer_cleanup, the Drop fallback, or an awaited cleanup whose caller was cancelled are retained and returned exactly once. Cleanup submitted concurrently after the barrier begins is covered by a later drain. A failure that may leave a residual database closes new admission so storage cannot accumulate without bound.

Source

pub async fn empty_database(&self) -> Result<DatabaseLease>

Creates a pristine database from PostgreSQL’s built-in template0.

Source

pub async fn template<F, Fut>( &self, spec: TemplateSpec, initializer: F, ) -> Result<DatabaseTemplate>
where F: FnOnce(String) -> Fut, Fut: Future<Output = Result<(), BoxError>>,

Gets or initializes one immutable, content-addressed template database.

Calls with the same fingerprint on clones of this harness single-flight initialization and share one live template handle. The cache is weak: dropping the final DatabaseTemplate releases its retained PostgreSQL shared-lock session. Separate harness starts continue to coordinate through PostgreSQL advisory locks.

Trait Implementations§

Source§

impl Clone for PostgresHarness

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> IntoResult<T> for T

Source§

type Err = !

Source§

fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>

Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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