From 2c465168b6b6e78faf44d7eb061cc0a66b502850 Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Tue, 16 Jul 2024 16:06:38 +0100 Subject: [PATCH] Use local network services for testing --- .github/workflows/test.yaml | 12 ++++++++++-- README.md | 13 +++++++++++++ bindings/trycp_runner/src/lib.rs | 1 + bindings/trycp_runner/src/macros.rs | 14 ++++++++++++++ conductor-config-ci.yaml | 6 ++++++ scenarios/remote_call_rate/README.md | 2 +- scenarios/remote_call_rate/src/main.rs | 5 +++-- scenarios/two_party_countersigning/README.md | 2 +- scenarios/two_party_countersigning/src/main.rs | 5 +++-- 9 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 bindings/trycp_runner/src/macros.rs create mode 100644 conductor-config-ci.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2d28908a..413b9ff3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -158,25 +158,33 @@ jobs: - name: Smoke test - remote_call_rate run: | + # Start local network services + nix develop .#ci -c bash -c "hc-run-local-services --bootstrap-port 4422 --signal-port 4423 &" # Start a TryCP instance nix develop .#ci -c bash -c "source ./scripts/trycp.sh && start_trycp" # Run the scenario for 10 seconds - RUST_LOG=warn MIN_PEERS=2 nix run .#remote_call_rate -- --targets targets-ci.yaml --instances-per-target 2 --duration 10 --no-progress + RUST_LOG=warn CONDUCTOR_CONFIG="CI" MIN_PEERS=2 nix run .#remote_call_rate -- --targets targets-ci.yaml --instances-per-target 2 --duration 10 --no-progress # Stop the TryCP instance nix develop .#ci -c bash -c "source ./scripts/trycp.sh && stop_trycp" + # Stop local network services + nix develop .#ci -c bash -c "pkill --echo hc-run-local-services" - name: Smoke test - two_party_countersigning run: | + # Start local network services + nix develop .#ci -c bash -c "hc-run-local-services --bootstrap-port 4422 --signal-port 4423 &" # Start a TryCP instance nix develop .#ci -c bash -c "source ./scripts/trycp.sh && start_trycp" # Run the scenario for 10 seconds - RUST_LOG=warn MIN_PEERS=2 nix run .#two_party_countersigning -- --targets targets-ci.yaml --behaviour initiate:1 --behaviour participate:1 --instances-per-target 2 --duration 10 --no-progress + RUST_LOG=warn CONDUCTOR_CONFIG="CI" MIN_PEERS=2 nix run .#two_party_countersigning -- --targets targets-ci.yaml --behaviour initiate:1 --behaviour participate:1 --instances-per-target 2 --duration 10 --no-progress # Stop the TryCP instance nix develop .#ci -c bash -c "source ./scripts/trycp.sh && stop_trycp" + # Stop local network services + nix develop .#ci -c bash -c "pkill --echo hc-run-local-services" - name: Build scenario bundles run: | diff --git a/README.md b/README.md index 5155a042..15dbce20 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,19 @@ hc s clean && echo "1234" | hc s --piped create && echo "1234" | hc s --piped -f For more advanced scenarios or for distributed tests, this is not appropriate! +#### Running network services + +There is an alternate conductor configuration that is used in CI and for development. This is found in `conductor-config-ci.yaml`. +To use this configuration, you will need to start bootstrap and signal servers on the expected ports. You can do this with the +following command: + +```bash +hc-run-local-services --bootstrap-port 4422 --signal-port 4423 +``` + +You should then set the environment variable `CONDUCTOR_CONFIG="CI"`. The scenario you are running should recommend this +if it supports switching the Holochain conductor config that it uses. + #### Running scenarios Each scenario is expected to provide a README.md with at least: diff --git a/bindings/trycp_runner/src/lib.rs b/bindings/trycp_runner/src/lib.rs index 3531ffd5..8b25e7cb 100644 --- a/bindings/trycp_runner/src/lib.rs +++ b/bindings/trycp_runner/src/lib.rs @@ -2,6 +2,7 @@ mod cli; mod common; mod context; mod definition; +mod macros; mod runner_context; pub mod prelude { diff --git a/bindings/trycp_runner/src/macros.rs b/bindings/trycp_runner/src/macros.rs new file mode 100644 index 00000000..c4cbe52a --- /dev/null +++ b/bindings/trycp_runner/src/macros.rs @@ -0,0 +1,14 @@ +#[macro_export] +macro_rules! embed_conductor_config { + () => { + fn conductor_config() -> &'static str { + static CONDUCTOR_CONFIG: &str = include_str!("../../../conductor-config.yaml"); + static CONDUCTOR_CONFIG_CI: &str = include_str!("../../../conductor-config-ci.yaml"); + + match std::env::var("CONDUCTOR_CONFIG") { + Ok(value) if value == "CI" => CONDUCTOR_CONFIG_CI, + _ => CONDUCTOR_CONFIG, + } + } + }; +} diff --git a/conductor-config-ci.yaml b/conductor-config-ci.yaml new file mode 100644 index 00000000..213fd207 --- /dev/null +++ b/conductor-config-ci.yaml @@ -0,0 +1,6 @@ +network: + network_type: quic_bootstrap + transport_pool: + - type: webrtc + signal_url: "ws://localhost:4423" + bootstrap_service: "http://localhost:4422" diff --git a/scenarios/remote_call_rate/README.md b/scenarios/remote_call_rate/README.md index 4d6fb98f..c788b36f 100644 --- a/scenarios/remote_call_rate/README.md +++ b/scenarios/remote_call_rate/README.md @@ -24,7 +24,7 @@ This configuration defaults to 2 peers. You can run the scenario locally with the following command: ```bash -RUST_LOG=info MIN_PEERS=2 cargo run --package remote_call_rate -- --targets targets-ci.yaml --instances-per-target 2 --duration 300 +RUST_LOG=info CONDUCTOR_CONFIG="CI" MIN_PEERS=2 cargo run --package remote_call_rate -- --targets targets-ci.yaml --instances-per-target 2 --duration 300 ``` This assumes that `trycp_server` is running. See the script `scripts/trycp.sh` and run with `start_trycp`. diff --git a/scenarios/remote_call_rate/src/main.rs b/scenarios/remote_call_rate/src/main.rs index 67e11c1a..f498c23f 100644 --- a/scenarios/remote_call_rate/src/main.rs +++ b/scenarios/remote_call_rate/src/main.rs @@ -4,9 +4,10 @@ use rand::seq::SliceRandom; use rand::thread_rng; use remote_call_integrity::TimedResponse; use std::time::{Duration, Instant}; +use trycp_wind_tunnel_runner::embed_conductor_config; use trycp_wind_tunnel_runner::prelude::*; -const CONDUCTOR_CONFIG: &str = include_str!("../../../conductor-config.yaml"); +embed_conductor_config!(); #[derive(Debug, Default)] pub struct ScenarioValues { @@ -28,7 +29,7 @@ fn agent_setup( .executor() .execute_in_place(async move { client - .configure_player(agent_name.clone(), CONDUCTOR_CONFIG.to_string(), None) + .configure_player(agent_name.clone(), conductor_config().to_string(), None) .await?; client diff --git a/scenarios/two_party_countersigning/README.md b/scenarios/two_party_countersigning/README.md index 39ee4e7f..2147d2a5 100644 --- a/scenarios/two_party_countersigning/README.md +++ b/scenarios/two_party_countersigning/README.md @@ -24,7 +24,7 @@ This configuration defaults to 2 peers. You can run the scenario locally with the following command: ```bash -RUST_LOG=OFF MIN_PEERS=5 cargo run --package two_party_countersigning -- --targets targets-ci.yaml --behaviour initiate:2 --behaviour participate:3 --instances-per-target 5 --duration 300 +RUST_LOG=info CONDUCTOR_CONFIG="CI" MIN_PEERS=5 cargo run --package two_party_countersigning -- --targets targets-ci.yaml --behaviour initiate:2 --behaviour participate:3 --instances-per-target 5 --duration 300 ``` This assumes that `trycp_server` is running. See the script `scripts/trycp.sh` and run with `start_trycp`. diff --git a/scenarios/two_party_countersigning/src/main.rs b/scenarios/two_party_countersigning/src/main.rs index be2de0b4..cfc256ea 100644 --- a/scenarios/two_party_countersigning/src/main.rs +++ b/scenarios/two_party_countersigning/src/main.rs @@ -9,9 +9,10 @@ use std::sync::atomic::AtomicUsize; use std::sync::Arc; use std::time::Duration; use tokio::time::Instant; +use trycp_wind_tunnel_runner::embed_conductor_config; use trycp_wind_tunnel_runner::prelude::*; -const CONDUCTOR_CONFIG: &str = include_str!("../../../conductor-config.yaml"); +embed_conductor_config!(); #[derive(Debug, Default)] pub struct ScenarioValues { @@ -35,7 +36,7 @@ fn agent_setup( .executor() .execute_in_place(async move { client - .configure_player(agent_name.clone(), CONDUCTOR_CONFIG.to_string(), None) + .configure_player(agent_name.clone(), conductor_config().to_string(), None) .await?; client