mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 14:49:21 +00:00
node: only fail test if failure rate is >50%
This commit is contained in:
parent
e0d22f3f9e
commit
31b1545d40
3 changed files with 34 additions and 6 deletions
6
.github/workflows/ping.yml
vendored
6
.github/workflows/ping.yml
vendored
|
@ -1,10 +1,14 @@
|
|||
# This uses the unit test in the [node.rs] file to ping all REMOTE_NODES
|
||||
# and attempts to serialize their JSON data to make sure they are working.
|
||||
|
||||
name: Daily Remote Node Ping
|
||||
name: Remote Node Ping
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 4 * * *"
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
|
|
@ -7,7 +7,7 @@ Gupax is a GUI for mining [**Monero**](https://github.com/monero-project/monero)
|
|||
|
||||
[![Windows](https://github.com/hinto-janai/gupax/actions/workflows/windows.yml/badge.svg)](https://github.com/hinto-janai/gupax/actions/workflows/windows.yml) [![macOS](https://github.com/hinto-janai/gupax/actions/workflows/macos.yml/badge.svg)](https://github.com/hinto-janai/gupax/actions/workflows/macos.yml) [![Linux](https://github.com/hinto-janai/gupax/actions/workflows/linux.yml/badge.svg)](https://github.com/hinto-janai/gupax/actions/workflows/linux.yml)
|
||||
|
||||
[![Daily Remote Node Ping](https://github.com/hinto-janai/gupax/actions/workflows/ping.yml/badge.svg)](https://github.com/hinto-janai/gupax/actions/workflows/ping.yml)
|
||||
[![Remote Node Ping](https://github.com/hinto-janai/gupax/actions/workflows/ping.yml/badge.svg)](https://github.com/hinto-janai/gupax/actions/workflows/ping.yml)
|
||||
|
||||
</div>
|
||||
|
||||
|
|
32
src/node.rs
32
src/node.rs
|
@ -446,9 +446,15 @@ mod test {
|
|||
// Random User Agent
|
||||
let rand_user_agent = crate::Pkg::get_user_agent();
|
||||
|
||||
// Only fail this test if >50% of nodes fail.
|
||||
const HALF_REMOTE_NODES: usize = REMOTE_NODE_LENGTH / 2;
|
||||
// A string buffer to append the failed node data.
|
||||
let mut failures = String::new();
|
||||
let mut failure_count = 0;
|
||||
|
||||
let mut n = 1;
|
||||
for (ip, _, rpc, zmq) in REMOTE_NODES {
|
||||
println!("[{}/{}] {} | {} | {}", n, REMOTE_NODE_LENGTH, ip, rpc, zmq);
|
||||
'outer: for (ip, _, rpc, zmq) in REMOTE_NODES {
|
||||
println!("[{n}/{REMOTE_NODE_LENGTH}] {ip} | {rpc} | {zmq}");
|
||||
let client = client.clone();
|
||||
// Try 5 times before failure
|
||||
let mut i = 1;
|
||||
|
@ -463,8 +469,13 @@ mod test {
|
|||
Ok(response) => break response,
|
||||
Err(e) => {
|
||||
println!("{:#?}", e);
|
||||
if i > 5 { panic!("Node failure: {}:{}:{}", ip, rpc, zmq); }
|
||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||
if i > 5 {
|
||||
use std::fmt::Write;
|
||||
writeln!(failures, "Node failure: {ip}:{rpc}:{zmq}");
|
||||
failure_count += 1;
|
||||
continue 'outer;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
@ -475,5 +486,18 @@ mod test {
|
|||
assert!(getinfo.jsonrpc == "2.0");
|
||||
n += 1;
|
||||
}
|
||||
|
||||
let failure_percent = failure_count as f32 / HALF_REMOTE_NODES as f32;
|
||||
|
||||
// If more than half the nodes fail, something
|
||||
// is definitely wrong, fail this test.
|
||||
if failure_count > HALF_REMOTE_NODES {
|
||||
panic!("[{failure_percent:.2}% of nodes failed, failure log:\n{failures}");
|
||||
// If some failures happened, log.
|
||||
} else if failure_count != 0 {
|
||||
eprintln!("[{failure_count}] nodes failed ({failure_percent:.2}%):\n{failures}");
|
||||
} else {
|
||||
println!("No nodes failed - all OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue