diff --git a/core/e2e/src/container.rs b/core/e2e/src/container.rs deleted file mode 100644 index 7411237db..000000000 --- a/core/e2e/src/container.rs +++ /dev/null @@ -1,99 +0,0 @@ -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; -use std::thread::JoinHandle; -use std::time::Duration; - -use lightning_interfaces::prelude::*; -use tokio::sync::Notify; - -use crate::containerized_node::RuntimeType; - -pub struct Container { - join_handle: Option>, - shutdown_notify: Option>, - syncronizer: Option>, - blockstore: Option, -} - -impl Drop for Container { - fn drop(&mut self) { - self.shutdown(); - } -} - -impl Container { - pub async fn spawn( - index: usize, - config: C::ConfigProviderInterface, - runtime_type: RuntimeType, - ) -> Self { - let shutdown_notify = Arc::new(Notify::new()); - let shutdown_notify_rx = shutdown_notify.clone(); - - let (tx, rx) = tokio::sync::oneshot::channel(); - let handle = std::thread::Builder::new() - .name(format!("NODE-{index}#MAIN")) - .spawn(move || { - let mut builder = match runtime_type { - RuntimeType::SingleThreaded => tokio::runtime::Builder::new_current_thread(), - RuntimeType::MultiThreaded => tokio::runtime::Builder::new_multi_thread(), - }; - - let runtime = builder - .thread_name_fn(move || { - static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0); - let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst); - format!("NODE-{index}#{id}") - }) - .enable_all() - .build() - .expect("Failed to build tokio runtime for node container."); - - runtime.block_on(async move { - let mut node = Node::::init(config).unwrap(); - node.start().await; - - tokio::time::sleep(Duration::from_millis(10)).await; - - let syncronizer = node - .provider - .get::<::SyncronizerInterface>(); - let blockstore = node - .provider - .get::<::BlockstoreInterface>() - .clone(); - - tx.send((syncronizer, blockstore)).ok(); - - shutdown_notify_rx.notified().await; - node.shutdown().await; - }); - }) - .expect("Failed to spawn E2E thread"); - - let (syncronizer, blockstore) = rx.await.expect("Failed to receive"); - - Self { - join_handle: Some(handle), - shutdown_notify: Some(shutdown_notify), - syncronizer: Some(syncronizer), - blockstore: Some(blockstore), - } - } - - pub fn shutdown(&mut self) { - if let Some(handle) = self.join_handle.take() { - let shutdown_notify = self.shutdown_notify.take().unwrap(); - shutdown_notify.notify_one(); - handle.join().expect("Failed to shutdown container."); - } - } - - pub fn take_ckpt_rx(&mut self) -> Option> { - self.syncronizer.take() - } - - pub fn take_blockstore(&mut self) -> Option { - self.blockstore.take() - } -} diff --git a/core/e2e/src/containerized_node.rs b/core/e2e/src/containerized_node.rs index 7062ad38a..dee4f447b 100644 --- a/core/e2e/src/containerized_node.rs +++ b/core/e2e/src/containerized_node.rs @@ -51,10 +51,6 @@ impl ContainerizedNode { self.node.shutdown() } - //pub fn is_running(&self) -> bool { - // self.node.lock().unwrap().is_some() - //} - pub fn get_rpc_address(&self) -> String { let config = self.config.get::>(); format!("http://{}", config.addr()) @@ -89,8 +85,3 @@ impl ContainerizedNode { self.is_genesis_committee } } - -pub enum RuntimeType { - SingleThreaded, - MultiThreaded, -} diff --git a/core/e2e/src/lib.rs b/core/e2e/src/lib.rs index 76365a2dd..570574247 100644 --- a/core/e2e/src/lib.rs +++ b/core/e2e/src/lib.rs @@ -1,4 +1,3 @@ -pub mod container; pub mod containerized_node; pub mod swarm; pub mod utils;