mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-05-17 07:09:28 +00:00
refactor(compose): simplify attach test to project-only source
This commit is contained in:
parent
5568902b46
commit
25d5a4859b
@ -2,7 +2,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Result, anyhow};
|
||||||
use lb_ext::{CoreBuilderExt as _, LbcComposeDeployer, LbcExtEnv, ScenarioBuilder};
|
use lb_ext::{CoreBuilderExt as _, LbcComposeDeployer, LbcExtEnv, ScenarioBuilder};
|
||||||
use testing_framework_core::scenario::{Deployer as _, Runner};
|
use testing_framework_core::scenario::{AttachSource, Deployer as _, Runner};
|
||||||
use testing_framework_runner_compose::{ComposeDeploymentMetadata, ComposeRunnerError};
|
use testing_framework_runner_compose::{ComposeDeploymentMetadata, ComposeRunnerError};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -21,13 +21,11 @@ async fn compose_attach_mode_restart_node_opt_in() -> Result<()> {
|
|||||||
Err(error) => return Err(anyhow::Error::new(error)),
|
Err(error) => return Err(anyhow::Error::new(error)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let services = metadata
|
let project_name = metadata
|
||||||
.discover_services()
|
.project_name()
|
||||||
.await
|
.ok_or_else(|| anyhow!("compose deployment metadata has no project name"))?
|
||||||
.map_err(|err| anyhow!("{err}"))?;
|
.to_owned();
|
||||||
let attach_source = metadata
|
let attach_source = AttachSource::compose(vec![]).with_project(project_name);
|
||||||
.attach_source_for_services(services.clone())
|
|
||||||
.map_err(|err| anyhow!("{err}"))?;
|
|
||||||
|
|
||||||
let attached = ScenarioBuilder::deployment_with(|d| d.with_node_count(1))
|
let attached = ScenarioBuilder::deployment_with(|d| d.with_node_count(1))
|
||||||
.enable_node_control()
|
.enable_node_control()
|
||||||
@ -46,6 +44,17 @@ async fn compose_attach_mode_restart_node_opt_in() -> Result<()> {
|
|||||||
.node_control()
|
.node_control()
|
||||||
.ok_or_else(|| anyhow!("attached compose node control is unavailable"))?;
|
.ok_or_else(|| anyhow!("attached compose node control is unavailable"))?;
|
||||||
|
|
||||||
|
let services: Vec<String> = attached_runner
|
||||||
|
.context()
|
||||||
|
.borrowed_nodes()
|
||||||
|
.into_iter()
|
||||||
|
.map(|node| node.identity)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if services.is_empty() {
|
||||||
|
return Err(anyhow!("attached compose runner discovered no services"));
|
||||||
|
}
|
||||||
|
|
||||||
for service in services {
|
for service in services {
|
||||||
let pre_restart_started_at = metadata
|
let pre_restart_started_at = metadata
|
||||||
.service_started_at(&service)
|
.service_started_at(&service)
|
||||||
|
|||||||
@ -50,21 +50,6 @@ impl ComposeDeploymentMetadata {
|
|||||||
Ok(AttachSource::compose(services).with_project(project_name.to_owned()))
|
Ok(AttachSource::compose(services).with_project(project_name.to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Discovers compose node services and builds an attach source for them.
|
|
||||||
pub async fn attach_source_for_discovered_services(&self) -> Result<AttachSource, DynError> {
|
|
||||||
let services = self.discover_services().await?;
|
|
||||||
self.attach_source_for_services(services)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Discovers node services for this compose deployment.
|
|
||||||
pub async fn discover_services(&self) -> Result<Vec<String>, DynError> {
|
|
||||||
let Some(project_name) = self.project_name() else {
|
|
||||||
return Err("compose metadata has no project name".into());
|
|
||||||
};
|
|
||||||
|
|
||||||
crate::docker::attached::discover_attachable_services(project_name).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the current StartedAt timestamp for a compose service container.
|
/// Returns the current StartedAt timestamp for a compose service container.
|
||||||
pub async fn service_started_at(&self, service: &str) -> Result<String, DynError> {
|
pub async fn service_started_at(&self, service: &str) -> Result<String, DynError> {
|
||||||
let Some(project_name) = self.project_name() else {
|
let Some(project_name) = self.project_name() else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user