Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/boot_fake_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,15 @@ pub fn run_runtime(
args: &[&str],
verbose: bool,
detached: bool,
verbosity: u8,
) -> anyhow::Result<(Child, OwnedFd)> {
let port = format!("{}", port);
let network_router_port = format!("{}", network_router_port);
let verbosity = format!("{}", verbosity);
let mut full_args = vec![
home.to_str().unwrap(), "--port", port.as_str(),
"--network-router-port", network_router_port.as_str(),
"--verbosity", verbosity.as_str(),
];

if !args.is_empty() {
Expand Down Expand Up @@ -367,6 +370,7 @@ pub async fn execute(
password: &str,
is_persist: bool,
release: bool,
verbosity: u8,
mut args: Vec<&str>,
) -> anyhow::Result<()> {
let detached = false; // TODO: to argument?
Expand Down Expand Up @@ -454,6 +458,7 @@ pub async fn execute(
&args[..],
true,
detached,
verbosity,
)?;

let mut node_cleanup_infos = node_cleanup_infos.lock().await;
Expand Down
17 changes: 14 additions & 3 deletions src/inject_message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct Response {
pub lazy_load_blob: Option<Vec<u8>>,
}

const ENDPOINT: &str = "/rpc:distro:sys/message";

impl std::fmt::Display for Response {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(Some(ref s)) = self.lazy_load_blob_utf8 {
Expand Down Expand Up @@ -76,16 +78,25 @@ pub async fn send_request(
url: &str,
json_data: Value,
) -> anyhow::Result<reqwest::Response> {
let endpoint = "/rpc:distro:sys/message";
send_request_inner(url, json_data).await
}

/// send_request_inner() allows failure without logging;
/// used for run_tests where nodes are pinged until they
/// respond with a 200 to determine when they are online
pub async fn send_request_inner(
url: &str,
json_data: Value,
) -> anyhow::Result<reqwest::Response> {
let mut url = url.to_string();
let url =
if url.ends_with(endpoint) {
if url.ends_with(ENDPOINT) {
url
} else {
if url.ends_with('/') {
url.pop();
}
format!("{}{}", url, endpoint)
format!("{}{}", url, ENDPOINT)
};
let client = reqwest::Client::new();
let response = client.post(&url)
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ async fn execute(
let password = boot_matches.get_one::<String>("PASSWORD").unwrap();
let is_persist = boot_matches.get_one::<bool>("PERSIST").unwrap();
let release = boot_matches.get_one::<bool>("RELEASE").unwrap();
let verbosity = boot_matches.get_one::<u8>("VERBOSITY").unwrap();

boot_fake_node::execute(
runtime_path,
Expand All @@ -144,6 +145,7 @@ async fn execute(
password,
*is_persist,
*release,
*verbosity,
vec![],
).await
},
Expand Down Expand Up @@ -398,6 +400,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> anyhow::Result<Command> {
.help("If set and given --runtime-path, compile release build [default: debug build]")
.required(false)
)
.arg(Arg::new("VERBOSITY")
.action(ArgAction::Set)
.long("verbosity")
.help("Verbosity of node: higher is more verbose")
.default_value("0")
.value_parser(value_parser!(u8))
)
.arg(Arg::new("help")
.long("help")
.action(ArgAction::Help)
Expand Down
13 changes: 7 additions & 6 deletions src/run_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async fn wait_until_booted(
None,
)?;

match inject_message::send_request(
match inject_message::send_request_inner(
&format!("http://localhost:{}", port),
request,
).await {
Expand Down Expand Up @@ -288,10 +288,10 @@ async fn run_tests(
#[instrument(level = "trace", err, skip_all)]
async fn handle_test(detached: bool, runtime_path: &Path, test: Test) -> anyhow::Result<()> {
for setup_package_path in &test.setup_package_paths {
build::execute(&setup_package_path, false, false, test.package_build_verbose, false).await?;
build::execute(&setup_package_path, false, false, !test.mute_package_build, false).await?;
}
for TestPackage { ref path, .. } in &test.test_packages {
build::execute(path, false, false, test.package_build_verbose, false).await?;
build::execute(path, false, false, !test.mute_package_build, false).await?;
}

// Initialize variables for master node and nodes list
Expand Down Expand Up @@ -355,7 +355,7 @@ async fn handle_test(detached: bool, runtime_path: &Path, test: Test) -> anyhow:
args.extend_from_slice(&["--password", password]);
};
if node.is_testnet {
args.extend_from_slice(&["--testnet"]);
args.push("--testnet");
}

let (runtime_process, master_fd) = run_runtime(
Expand All @@ -364,8 +364,9 @@ async fn handle_test(detached: bool, runtime_path: &Path, test: Test) -> anyhow:
node.port,
test.network_router.port,
&args[..],
node.runtime_verbose,
!node.mute_runtime,
detached,
node.runtime_verbosity.unwrap_or_else(|| 0u8),
)?;

let mut node_cleanup_infos = node_cleanup_infos.lock().await;
Expand Down Expand Up @@ -439,7 +440,7 @@ pub async fn execute(config_path: &str) -> anyhow::Result<()> {
// Compile the runtime binary
compile_runtime(
&runtime_path,
config.runtime_build_verbose,
!config.mute_runtime_build,
config.runtime_build_release,
)?;
runtime_path.join("target")
Expand Down
7 changes: 4 additions & 3 deletions src/run_tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub runtime: Runtime,
pub runtime_build_verbose: bool,
pub mute_runtime_build: bool,
pub runtime_build_release: bool,
pub tests: Vec<Test>,
}
Expand All @@ -25,7 +25,7 @@ pub enum Runtime {
pub struct Test {
pub setup_package_paths: Vec<PathBuf>,
pub test_packages: Vec<TestPackage>,
pub package_build_verbose: bool,
pub mute_package_build: bool,
pub timeout_secs: u64,
pub network_router: NetworkRouter,
pub nodes: Vec<Node>,
Expand Down Expand Up @@ -56,8 +56,9 @@ pub struct Node {
pub fake_node_name: String,
pub password: Option<String>,
pub rpc: Option<String>,
pub runtime_verbose: bool,
pub mute_runtime: bool,
pub is_testnet: bool,
pub runtime_verbosity: Option<u8>,
}

pub type NodeHandles = Arc<Mutex<Vec<Child>>>;
Expand Down