Skip to content

Commit

Permalink
add Op::DebugFailedNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
haxjump committed Oct 20, 2024
1 parent ae85ff7 commit 8574c18
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chaindev"
version = "0.42.1"
version = "0.42.2"
edition = "2021"
authors = ["hui.fan@mail.ru"]
description = "Powerful development and testing utils for blockchain developers."
Expand Down
57 changes: 57 additions & 0 deletions src/beacon_based/ddev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ where
env.show();
}),
Op::ShowAll => Env::<C, P, S>::show_all().c(d!()),
Op::DebugFailedNodes => Env::<C, P, S>::load_env_by_cfg(self)
.c(d!())
.and_then(|env| env.debug_failed_nodes().c(d!())),
Op::List => Env::<C, P, S>::list_all().c(d!()),
Op::HostPutFile {
local_path,
Expand Down Expand Up @@ -1047,6 +1050,59 @@ where
Ok(())
}

fn debug_failed_nodes(&self) -> Result<()> {
let mut failed_cases = vec![];
let mut errlist: Vec<Box<dyn RucError>> = vec![];

for nodes in self
.meta
.nodes
.values()
.chain(self.meta.fuhrers.values())
.collect::<Vec<_>>()
.chunks(24)
{
thread::scope(|s| {
nodes
.iter()
.map(|n| {
let cmd =
self.node_cmdline_generator.cmd_cnt_running(n, &self.meta);
s.spawn(move || {
let process_cnt = Remote::from(&n.host)
.exec_cmd(&cmd)
.c(d!())?
.trim()
.parse::<u64>()
.c(d!())?;
if 3 > process_cnt {
Ok((n, true)) // failed status
} else {
Ok((n, false)) // well status
}
})
})
.collect::<Vec<_>>()
.into_iter()
.flat_map(|hdr| hdr.join())
.for_each(|ret| match ret {
Ok((n, failed)) => {
if failed {
failed_cases.push((n.id, n.host.host_id()));
}
}
Err(e) => {
errlist.push(e);
}
});
})
}

println!("{}", serde_json::to_string_pretty(&failed_cases).c(d!())?);

check_errlist!(errlist)
}

// List the names of all existing ENVs
fn list_all() -> Result<()> {
let list = Self::get_env_list().c(d!())?;
Expand Down Expand Up @@ -1680,6 +1736,7 @@ where
StopAll(bool /*force or not*/),
Show,
ShowAll,
DebugFailedNodes,
List,
HostPutFile {
local_path: String,
Expand Down
24 changes: 24 additions & 0 deletions src/beacon_based/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ where
})
}
Op::ShowAll => Env::<Data, Ports, Cmds>::show_all().c(d!()),
Op::DebugFailedNodes => Env::<Data, Ports, Cmds>::load_env_by_cfg(self)
.c(d!())
.and_then(|env| env.debug_failed_nodes().c(d!())),
Op::List => Env::<Data, Ports, Cmds>::list_all().c(d!()),
Op::Custom(custom_op) => custom_op.exec(&self.name).c(d!()),
Op::Nil(_) => unreachable!(),
Expand Down Expand Up @@ -595,6 +598,26 @@ where
Ok(())
}

fn debug_failed_nodes(&self) -> Result<()> {
let mut failed_cases = vec![];

for n in self.meta.nodes.values().chain(self.meta.fuhrers.values()) {
let cmd = self.node_cmdline_generator.cmd_cnt_running(n, &self.meta);
let process_cnt = cmd::exec_output(&cmd)
.c(d!(&cmd))?
.trim()
.parse::<u64>()
.c(d!())?;
if 3 > process_cnt {
failed_cases.push(n.id);
}
}

serde_json::to_string_pretty(&failed_cases)
.c(d!())
.map(|s| println!("{s}"))
}

// list the names of all existing ENVs
fn list_all() -> Result<()> {
let list = Self::get_env_list().c(d!())?;
Expand Down Expand Up @@ -1029,6 +1052,7 @@ where
StopAll(bool /*force or not*/),
Show,
ShowAll,
DebugFailedNodes,
List,
Custom(Ops),
Nil(Ports),
Expand Down

0 comments on commit 8574c18

Please sign in to comment.