Skip to content

Commit

Permalink
Log
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Jan 2, 2025
1 parent e0623b6 commit 8a1c33f
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions crates/e2e/src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ async fn run<F, Fut, T>(
let _lock = NODE_MUTEX.lock();

let (node, web3) = spawn_node_with_retries(&fork, 3).await;
tracing::info!("Node started");

services::clear_database().await;
// Hack: the closure may actually be unwind unsafe; moreover, `catch_unwind`
Expand All @@ -203,10 +204,9 @@ async fn run<F, Fut, T>(
// is supposed to be used in a test environment.
let result = AssertUnwindSafe(f(web3.clone())).catch_unwind().await;

let node = node.lock().unwrap().take();
if let Some(mut node) = node {
node.kill().await;
}
let mut node = node.lock().unwrap();
node.kill().await;

services::clear_database().await;

if let Err(err) = result {
Expand All @@ -216,18 +216,18 @@ async fn run<F, Fut, T>(

async fn try_spawn_node_and_check(
fork: &Option<(String, Option<u64>)>,
) -> Option<(Arc<Mutex<Option<Node>>>, Web3)> {
) -> Option<(Arc<Mutex<Node>>, Web3)> {
let node = match fork {
Some((fork_url, block_number)) => Node::forked(fork_url.clone(), *block_number).await,
None => Node::new().await,
};
let node = Arc::new(Mutex::new(Some(node)));
let node = Arc::new(Mutex::new(node));

let node_panic_handle = node.clone();
observe::panic_hook::prepend_panic_handler(Box::new(move |_| {
// Drop node in panic handler because `.catch_unwind()` does not catch all
// panics
let _ = node_panic_handle.lock().unwrap().take();
let _ = node_panic_handle.lock().unwrap();
}));

let http = create_test_transport(NODE_HOST);
Expand All @@ -241,8 +241,11 @@ async fn try_spawn_node_and_check(
match mine_check {
Ok(Ok(_)) => Some((node, web3)),
_ => {
let node = node.lock().unwrap().take();
if let Some(mut node) = node {
let node_to_kill = {
let mut guard = node.lock().unwrap();
guard.take()
};
if let Some(mut node) = node_to_kill {
node.kill().await;
}
None
Expand All @@ -253,7 +256,7 @@ async fn try_spawn_node_and_check(
async fn spawn_node_with_retries(
fork: &Option<(String, Option<u64>)>,
max_attempts: u32,
) -> (Arc<Mutex<Option<Node>>>, Web3) {
) -> (Arc<Mutex<Node>>, Web3) {
let mut attempts = 0;

while attempts < max_attempts {
Expand Down

0 comments on commit 8a1c33f

Please sign in to comment.