Skip to content

Commit

Permalink
Use local network services for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Jul 16, 2024
1 parent 1d7212c commit 2c46516
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 8 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions bindings/trycp_runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod cli;
mod common;
mod context;
mod definition;
mod macros;
mod runner_context;

pub mod prelude {
Expand Down
14 changes: 14 additions & 0 deletions bindings/trycp_runner/src/macros.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
};
}
6 changes: 6 additions & 0 deletions conductor-config-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
network:
network_type: quic_bootstrap
transport_pool:
- type: webrtc
signal_url: "ws://localhost:4423"
bootstrap_service: "http://localhost:4422"
2 changes: 1 addition & 1 deletion scenarios/remote_call_rate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 3 additions & 2 deletions scenarios/remote_call_rate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scenarios/two_party_countersigning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 3 additions & 2 deletions scenarios/two_party_countersigning/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 2c46516

Please sign in to comment.