Revert "fix: tests"

This reverts commit 0949458d85.
This commit is contained in:
Cyrix126 2024-10-11 17:49:00 +02:00
parent e5c333861c
commit 1d7837e700
2 changed files with 88 additions and 0 deletions

View file

@ -135,6 +135,93 @@ Uptime = 0h 2m 4s
assert_eq!(public.xmr_month, 648000.0000001296); assert_eq!(public.xmr_month, 648000.0000001296);
} }
#[test]
fn set_p2pool_synchronized() {
use crate::helper::PubP2poolApi;
use std::sync::{Arc, Mutex};
let public = Arc::new(Mutex::new(PubP2poolApi::new()));
let output_parse = Arc::new(Mutex::new(String::from(
r#"payout of 5.000000000001 XMR in block 1111
NOTICE 2021-12-27 21:42:17.2008 SideChain SYNCHRONIZED
payout of 5.000000000001 XMR in block 1113"#,
)));
let output_pub = Arc::new(Mutex::new(String::new()));
let elapsed = std::time::Duration::from_secs(60);
let process = Arc::new(Mutex::new(Process::new(
ProcessName::P2pool,
"".to_string(),
PathBuf::new(),
)));
// It only gets checked if we're `Syncing`.
process.lock().unwrap().state = ProcessState::Syncing;
PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &process);
println!("{:#?}", process);
assert!(process.lock().unwrap().state == ProcessState::Alive);
}
#[test]
fn p2pool_synchronized_false_positive() {
use crate::helper::PubP2poolApi;
use std::sync::{Arc, Mutex};
let public = Arc::new(Mutex::new(PubP2poolApi::new()));
// The SideChain that is "SYNCHRONIZED" in this output is
// probably not main/mini, but the sidechain started on height 1,
// so this should _not_ trigger alive state.
let output_parse = Arc::new(Mutex::new(String::from(
r#"payout of 5.000000000001 XMR in block 1111
SideChain new chain tip: next height = 1
NOTICE 2021-12-27 21:42:17.2008 SideChain SYNCHRONIZED
payout of 5.000000000001 XMR in block 1113"#,
)));
let output_pub = Arc::new(Mutex::new(String::new()));
let elapsed = std::time::Duration::from_secs(60);
let process = Arc::new(Mutex::new(Process::new(
ProcessName::P2pool,
"".to_string(),
PathBuf::new(),
)));
// It only gets checked if we're `Syncing`.
process.lock().unwrap().state = ProcessState::Syncing;
PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &process);
println!("{:#?}", process);
assert!(process.lock().unwrap().state == ProcessState::Syncing); // still syncing
}
#[test]
fn p2pool_synchronized_double_synchronized() {
use crate::helper::PubP2poolApi;
use std::sync::{Arc, Mutex};
let public = Arc::new(Mutex::new(PubP2poolApi::new()));
// The 1st SideChain that is "SYNCHRONIZED" in this output is
// the sidechain started on height 1, but there is another one
// which means the real main/mini is probably synced,
// so this _should_ trigger alive state.
let output_parse = Arc::new(Mutex::new(String::from(
r#"payout of 5.000000000001 XMR in block 1111
SideChain new chain tip: next height = 1
NOTICE 2021-12-27 21:42:17.2008 SideChain SYNCHRONIZED
payout of 5.000000000001 XMR in block 1113
NOTICE 2021-12-27 21:42:17.2100 SideChain SYNCHRONIZED"#,
)));
let output_pub = Arc::new(Mutex::new(String::new()));
let elapsed = std::time::Duration::from_secs(60);
let process = Arc::new(Mutex::new(Process::new(
ProcessName::P2pool,
"".to_string(),
PathBuf::new(),
)));
// It only gets checked if we're `Syncing`.
process.lock().unwrap().state = ProcessState::Syncing;
PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &process);
println!("{:#?}", process);
assert!(process.lock().unwrap().state == ProcessState::Alive);
}
#[test] #[test]
fn update_pub_p2pool_from_local_network_pool() { fn update_pub_p2pool_from_local_network_pool() {
use crate::helper::p2pool::PoolStatistics; use crate::helper::p2pool::PoolStatistics;

View file

@ -284,6 +284,7 @@ mod test {
let r = P2poolRegex::new(); let r = P2poolRegex::new();
let text = "NOTICE 2022-11-11 11:11:11.1111 P2Pool You received a payout of 0.111111111111 XMR in block 1111111"; let text = "NOTICE 2022-11-11 11:11:11.1111 P2Pool You received a payout of 0.111111111111 XMR in block 1111111";
let text2 = "2022-11-11 11:11:11.1111 | 0.111111111111 XMR | Block 1,111,111"; let text2 = "2022-11-11 11:11:11.1111 | 0.111111111111 XMR | Block 1,111,111";
let text3 = "NOTICE 2020-12-11 12:35:41.3150 SideChain SYNCHRONIZED";
assert_eq!( assert_eq!(
r.payout.find(text).unwrap().as_str(), r.payout.find(text).unwrap().as_str(),
"payout of 0.111111111111 XMR" "payout of 0.111111111111 XMR"