From b1b3bacd1c2084ae4359321adcc46a37d3aa9829 Mon Sep 17 00:00:00 2001 From: Gregory Sobol Date: Fri, 6 Sep 2024 09:47:16 +0200 Subject: [PATCH] fix(ethexe): revert "feat(ethexe): introduce test-only field status for Service (#4182)" (#4227) --- ethexe/cli/src/service.rs | 44 --------------------------------- ethexe/cli/src/tests.rs | 52 +++++++++++---------------------------- 2 files changed, 15 insertions(+), 81 deletions(-) diff --git a/ethexe/cli/src/service.rs b/ethexe/cli/src/service.rs index dbb6820c2aa..8bd5d63cbd0 100644 --- a/ethexe/cli/src/service.rs +++ b/ethexe/cli/src/service.rs @@ -46,9 +46,6 @@ use std::{ }; use utils::*; -#[cfg(test)] -pub use {futures::lock::Mutex, tests::Status}; - /// ethexe service. pub struct Service { db: Database, @@ -64,10 +61,6 @@ pub struct Service { validator: Option, metrics_service: Option, rpc: Option, - - // service status - #[cfg(test)] - status: Arc>, } // TODO: consider to move this to another module #4176 @@ -198,8 +191,6 @@ impl Service { metrics_service, rpc, block_time: config.block_time, - #[cfg(test)] - status: Default::default(), }) } @@ -238,8 +229,6 @@ impl Service { validator, metrics_service, rpc, - #[cfg(test)] - status: Default::default(), } } @@ -427,8 +416,6 @@ impl Service { metrics_service, rpc, block_time, - #[cfg(test)] - status, } = self; if let Some(metrics_service) = metrics_service { @@ -472,11 +459,6 @@ impl Service { let mut collection_round_timer = StoppableTimer::new(block_time / 4); let mut validation_round_timer = StoppableTimer::new(block_time / 4); - #[cfg(test)] - { - *status.lock().await = Status::Active; - } - loop { tokio::select! { observer_event = observer_events.next() => { @@ -560,10 +542,6 @@ impl Service { } } - #[cfg(test)] - { - *status.lock().await = Status::Terminated; - } Ok(()) } @@ -804,12 +782,6 @@ impl Service { } } } - - #[cfg(test)] - /// Get the pointer of service status - pub fn status(&self) -> Arc> { - self.status.clone() - } } mod utils { @@ -871,22 +843,6 @@ mod tests { }; use tempfile::tempdir; - /// Service status - #[derive(Default, PartialEq)] - pub enum Status { - #[default] - Pending, - Active, - Terminated, - } - - impl Status { - /// If the service is active - pub fn active(&self) -> bool { - *self == Status::Active - } - } - #[tokio::test] async fn basics() { gear_utils::init_default_logger(); diff --git a/ethexe/cli/src/tests.rs b/ethexe/cli/src/tests.rs index 02bd2122498..db7989e3509 100644 --- a/ethexe/cli/src/tests.rs +++ b/ethexe/cli/src/tests.rs @@ -18,7 +18,7 @@ //! Integration tests. -use crate::service::{Service, Status}; +use crate::service::Service; use alloy::{ node_bindings::{Anvil, AnvilInstance}, providers::{ext::AnvilApi, Provider}, @@ -35,13 +35,10 @@ use ethexe_processor::Processor; use ethexe_sequencer::Sequencer; use ethexe_signer::Signer; use ethexe_validator::Validator; -use futures::{lock::Mutex, StreamExt}; +use futures::StreamExt; use gear_core::ids::prelude::*; use gprimitives::{ActorId, CodeId, MessageId, H160, H256}; -use std::{ - sync::Arc, - time::{Duration, SystemTime}, -}; +use std::{sync::Arc, time::Duration}; use tokio::{ sync::{ mpsc::{self, Receiver}, @@ -157,7 +154,6 @@ struct TestEnv { sender_address: ActorId, block_time: Duration, running_service_handle: Option>>, - service_status: Option>>, } impl TestEnv { @@ -237,7 +233,6 @@ impl TestEnv { sender_address: ActorId::from(H160::from(sender_address.0)), block_time, running_service_handle: None, - service_status: None, }; Ok(env) @@ -295,11 +290,13 @@ impl TestEnv { None, ); - self.service_status = Some(service.status()); - let handle = task::spawn(service.run()); self.running_service_handle = Some(handle); - self.service_initialized().await?; + + // Sleep to wait for the new service to start + // TODO: find a better way to wait for the service to start #4099 + tokio::time::sleep(Duration::from_secs(1)).await; + Ok(()) } @@ -328,26 +325,6 @@ impl TestEnv { Ok((tx_hash, code_id)) } - - /// Wait for service initialized - pub async fn service_initialized(&self) -> Result<()> { - let Some(status) = &self.service_status else { - return Err(anyhow!("Service not start")); - }; - - let now = SystemTime::now(); - loop { - if status.lock().await.active() { - return Ok(()); - } - - if now.elapsed()? > self.block_time { - break; - } - } - - Err(anyhow!("Service initialization timed out.")) - } } impl Drop for TestEnv { @@ -687,9 +664,9 @@ async fn ping_reorg() { .await .unwrap(); - env.service_initialized() - .await - .expect("service uninitalized"); + // Await for service block with user reply handling + // TODO: this is for better logs reading only, should find a better solution #4099 + tokio::time::sleep(env.block_time).await; log::info!("📗 Reverting to the program creation snapshot"); provider @@ -771,9 +748,10 @@ async fn ping_reorg() { .await .unwrap(); - env.service_initialized() - .await - .expect("service uninitalized"); + // Await for service block with user reply handling + // TODO: this is for better logs reading only, should find a better solution #4099 + tokio::time::sleep(Duration::from_secs(1)).await; + log::info!("📗 Done"); }