47 lines
1.4 KiB
Rust
Raw Normal View History

use std::time::Duration;
2026-02-02 07:19:22 +01:00
use testing_framework_core::scenario::{HttpReadinessRequirement, NodeClients};
use tokio::time::sleep;
use crate::{
2026-02-02 07:19:22 +01:00
env::ComposeDeployEnv,
errors::{NodeClientError, StackReadinessError},
2026-02-02 07:19:22 +01:00
infrastructure::ports::{HostPortMapping, compose_runner_host},
};
const DISABLED_READINESS_SLEEP: Duration = Duration::from_secs(5);
2026-01-26 08:26:15 +01:00
/// Wait until all nodes respond on their API ports.
2026-02-02 07:19:22 +01:00
pub async fn ensure_nodes_ready_with_ports<E: ComposeDeployEnv>(
ports: &[u16],
requirement: HttpReadinessRequirement,
) -> Result<(), StackReadinessError> {
if ports.is_empty() {
return Ok(());
}
2026-02-02 07:19:22 +01:00
let host = compose_runner_host();
E::wait_for_nodes(ports, &host, requirement)
.await
.map_err(|source| StackReadinessError::Remote { source })
}
/// Allow a brief pause when readiness probes are disabled.
pub async fn maybe_sleep_for_disabled_readiness(readiness_enabled: bool) {
2026-02-02 07:19:22 +01:00
if readiness_enabled {
return;
}
2026-02-02 07:19:22 +01:00
sleep(DISABLED_READINESS_SLEEP).await;
}
/// Construct API clients using the mapped host ports.
2026-02-02 07:19:22 +01:00
pub fn build_node_clients_with_ports<E: ComposeDeployEnv>(
descriptors: &E::Deployment,
mapping: &HostPortMapping,
host: &str,
2026-02-02 07:19:22 +01:00
) -> Result<NodeClients<E>, NodeClientError> {
E::build_node_clients(descriptors, mapping, host)
.map_err(|source| NodeClientError::Build { source })
}