pub struct PostgresHarness { /* private fields */ }Expand description
Process-local owner of a PostgreSQL 18 server and its database capacity.
Implementations§
Source§impl PostgresHarness
impl PostgresHarness
pub async fn start(config: HarnessConfig) -> Result<Self>
pub fn project(&self) -> &ProjectName
pub fn admin_database_url(&self) -> &str
pub fn is_external(&self) -> bool
Sourcepub fn container_id(&self) -> Option<&str>
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.
Sourcepub fn connection_limits(&self) -> ConnectionLimits
pub fn connection_limits(&self) -> ConnectionLimits
Returns the resolved downstream connection-permit policy used by this harness’s database admission control.
Sourcepub async fn shutdown(&self) -> Result<()>
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.
Sourcepub async fn drain_deferred_cleanup(&self) -> Result<()>
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.
Sourcepub async fn empty_database(&self) -> Result<DatabaseLease>
pub async fn empty_database(&self) -> Result<DatabaseLease>
Creates a pristine database from PostgreSQL’s built-in template0.
Sourcepub async fn template<F, Fut>(
&self,
spec: TemplateSpec,
initializer: F,
) -> Result<DatabaseTemplate>
pub async fn template<F, Fut>( &self, spec: TemplateSpec, initializer: F, ) -> Result<DatabaseTemplate>
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§
Auto Trait Implementations§
impl Freeze for PostgresHarness
impl RefUnwindSafe for PostgresHarness
impl Send for PostgresHarness
impl Sync for PostgresHarness
impl Unpin for PostgresHarness
impl UnsafeUnpin for PostgresHarness
impl UnwindSafe for PostgresHarness
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request