From 34a840cfacd00fca49f439369fa045f3c1134b5d Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 14 Apr 2023 13:45:30 -0400 Subject: [PATCH] tests: add p2pool sync test --- src/helper.rs | 28 +++++++++++++++++++++++++++- src/regex.rs | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/helper.rs b/src/helper.rs index a9b8b67..feb6a8b 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -121,6 +121,7 @@ impl Default for Sys { fn default() -> Self { Self::new() } } //---------------------------------------------------------------------------------------------------- [Process] Struct // This holds all the state of a (child) process. // The main GUI thread will use this to display console text, online state, etc. +#[derive(Debug)] pub struct Process { pub name: ProcessName, // P2Pool or XMRig? pub state: ProcessState, // The state of the process (alive, dead, etc) @@ -1900,6 +1901,8 @@ impl Hashrate { //---------------------------------------------------------------------------------------------------- TESTS #[cfg(test)] mod test { + use super::*; + #[test] fn reset_gui_output() { let max = crate::helper::GUI_OUTPUT_LEEWAY; @@ -1955,7 +1958,8 @@ mod test { let output_pub = Arc::new(Mutex::new(String::new())); let elapsed = std::time::Duration::from_secs(60); let regex = P2poolRegex::new(); - PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, ®ex); + let process = Arc::new(Mutex::new(Process::new(ProcessName::P2pool, "".to_string(), PathBuf::new()))); + PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, ®ex, &process); let public = public.lock().unwrap(); println!("{:#?}", public); assert_eq!(public.payouts, 3); @@ -1968,6 +1972,28 @@ mod test { assert_eq!(public.xmr_month, 648000.0000001296); } + #[test] + fn set_p2pool_synchronized() { + use crate::helper::{PubP2poolApi,P2poolRegex}; + 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 regex = P2poolRegex::new(); + 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, ®ex, &process); + println!("{:#?}", process); + assert!(process.lock().unwrap().state == ProcessState::Alive); + } + #[test] fn update_pub_p2pool_from_local_network_pool() { use std::sync::{Arc,Mutex}; diff --git a/src/regex.rs b/src/regex.rs index b13958e..cc9a21d 100644 --- a/src/regex.rs +++ b/src/regex.rs @@ -127,6 +127,6 @@ mod test { assert_eq!(r.block.find(text).unwrap().as_str(), "block 1111111"); assert_eq!(r.block_int.find(text).unwrap().as_str(), "1111111"); assert_eq!(r.block_comma.find(text2).unwrap().as_str(), "1,111,111"); - assert_eq!(r.synchronized.find(text2).unwrap().as_str(), "SYNCHRONIZED"); + assert_eq!(r.synchronized.find(text3).unwrap().as_str(), "SYNCHRONIZED"); } }