2026-03-06 13:31:03 +01:00
|
|
|
use std::time::Duration;
|
2026-03-02 11:19:55 +01:00
|
|
|
|
|
|
|
|
use anyhow::{Result, anyhow};
|
|
|
|
|
use lb_ext::{CoreBuilderExt as _, LbcComposeDeployer, LbcExtEnv, ScenarioBuilder};
|
2026-03-06 13:31:03 +01:00
|
|
|
use testing_framework_core::scenario::{Deployer as _, Runner};
|
|
|
|
|
use testing_framework_runner_compose::{ComposeDeploymentMetadata, ComposeRunnerError};
|
2026-03-02 11:19:55 +01:00
|
|
|
|
|
|
|
|
#[tokio::test]
|
2026-03-06 13:25:11 +01:00
|
|
|
#[ignore = "requires Docker and mutates compose runtime state"]
|
2026-03-02 11:19:55 +01:00
|
|
|
async fn compose_attach_mode_restart_node_opt_in() -> Result<()> {
|
|
|
|
|
let managed = ScenarioBuilder::deployment_with(|d| d.with_node_count(1))
|
|
|
|
|
.enable_node_control()
|
|
|
|
|
.with_run_duration(Duration::from_secs(5))
|
|
|
|
|
.build()?;
|
|
|
|
|
|
|
|
|
|
let deployer = LbcComposeDeployer::default();
|
2026-03-06 13:31:03 +01:00
|
|
|
let (_managed_runner, metadata): (Runner<LbcExtEnv>, ComposeDeploymentMetadata) =
|
2026-03-06 13:25:11 +01:00
|
|
|
match deployer.deploy_with_metadata(&managed).await {
|
|
|
|
|
Ok(result) => result,
|
|
|
|
|
Err(ComposeRunnerError::DockerUnavailable) => return Ok(()),
|
|
|
|
|
Err(error) => return Err(anyhow::Error::new(error)),
|
|
|
|
|
};
|
2026-03-02 11:19:55 +01:00
|
|
|
|
2026-03-06 13:47:25 +01:00
|
|
|
let services = metadata
|
|
|
|
|
.discover_services()
|
|
|
|
|
.await
|
|
|
|
|
.map_err(|err| anyhow!("{err}"))?;
|
|
|
|
|
let service = services
|
|
|
|
|
.first()
|
|
|
|
|
.cloned()
|
|
|
|
|
.ok_or_else(|| anyhow!("compose deployment metadata discovered no services"))?;
|
|
|
|
|
let attach_source = metadata
|
|
|
|
|
.attach_source_for_services(services)
|
|
|
|
|
.map_err(|err| anyhow!("{err}"))?;
|
|
|
|
|
|
2026-03-02 11:19:55 +01:00
|
|
|
let attached = ScenarioBuilder::deployment_with(|d| d.with_node_count(1))
|
|
|
|
|
.enable_node_control()
|
|
|
|
|
.with_run_duration(Duration::from_secs(5))
|
2026-03-06 13:47:25 +01:00
|
|
|
.with_attach_source(attach_source)
|
2026-03-02 11:19:55 +01:00
|
|
|
.build()?;
|
|
|
|
|
|
2026-03-06 13:25:11 +01:00
|
|
|
let attached_runner: Runner<LbcExtEnv> = match deployer.deploy(&attached).await {
|
|
|
|
|
Ok(runner) => runner,
|
|
|
|
|
Err(ComposeRunnerError::DockerUnavailable) => return Ok(()),
|
|
|
|
|
Err(error) => return Err(anyhow::Error::new(error)),
|
|
|
|
|
};
|
2026-03-06 13:31:03 +01:00
|
|
|
|
|
|
|
|
let pre_restart_started_at = metadata
|
2026-03-06 13:47:25 +01:00
|
|
|
.service_started_at(&service)
|
2026-03-06 13:31:03 +01:00
|
|
|
.await
|
|
|
|
|
.map_err(|err| anyhow!("{err}"))?;
|
|
|
|
|
|
2026-03-02 11:19:55 +01:00
|
|
|
let control = attached_runner
|
|
|
|
|
.context()
|
|
|
|
|
.node_control()
|
|
|
|
|
.ok_or_else(|| anyhow!("attached compose node control is unavailable"))?;
|
2026-03-06 13:31:03 +01:00
|
|
|
|
2026-03-02 11:19:55 +01:00
|
|
|
control
|
2026-03-06 13:47:25 +01:00
|
|
|
.restart_node(&service)
|
2026-03-02 11:19:55 +01:00
|
|
|
.await
|
|
|
|
|
.map_err(|err| anyhow!("attached restart failed: {err}"))?;
|
|
|
|
|
|
2026-03-06 13:31:03 +01:00
|
|
|
metadata
|
2026-03-06 13:47:25 +01:00
|
|
|
.wait_until_service_restarted(&service, &pre_restart_started_at, Duration::from_secs(30))
|
2026-03-06 13:31:03 +01:00
|
|
|
.await
|
|
|
|
|
.map_err(|err| anyhow!("{err}"))?;
|
2026-03-02 11:19:55 +01:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|