Skip to content

Commit

Permalink
fix(ethexe): fixing of ethexe tests hang on (#4071)
Browse files Browse the repository at this point in the history
  • Loading branch information
grishasobol authored Jul 22, 2024
1 parent 0bb231b commit 9471bc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 13 additions & 6 deletions ethexe/cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ use gear_core::ids::prelude::*;
use gprimitives::{ActorId, CodeId, H256};
use std::{sync::Arc, time::Duration};
use tokio::{
sync::mpsc::{self, Receiver},
sync::{
mpsc::{self, Receiver},
oneshot,
},
task::{self, JoinHandle},
};

Expand All @@ -44,17 +47,21 @@ struct Listener {
}

impl Listener {
pub fn new(mut observer: Observer) -> Self {
pub async fn new(mut observer: Observer) -> Self {
let (sender, receiver) = mpsc::channel::<Event>(1024);

let (send_subscription_created, receive_subscription_created) = oneshot::channel::<()>();
let _handle = task::spawn(async move {
let observer_events = observer.events();
futures::pin_mut!(observer_events);

send_subscription_created.send(()).unwrap();

while let Some(event) = observer_events.next().await {
sender.send(event).await.unwrap();
}
});
receive_subscription_created.await.unwrap();

Self { receiver, _handle }
}
Expand Down Expand Up @@ -198,8 +205,8 @@ impl TestEnv {
Ok(env)
}

pub fn new_listener(&self) -> Listener {
Listener::new(self.observer.clone())
pub async fn new_listener(&self) -> Listener {
Listener::new(self.observer.clone()).await
}

pub async fn upload_code(&self, code: &[u8]) -> Result<(H256, CodeId)> {
Expand All @@ -220,11 +227,11 @@ impl TestEnv {
async fn ping() {
gear_utils::init_default_logger();

let mut anvil = Anvil::new().block_time(1).try_spawn().unwrap();
let mut anvil = Anvil::new().try_spawn().unwrap();
drop(anvil.child_mut().stdout.take()); //temp fix for alloy#1078

let mut env = TestEnv::new(anvil.ws_endpoint()).await.unwrap();
let mut listener = env.new_listener();
let mut listener = env.new_listener().await;

let service = env.service.take().unwrap();
let service_handle = task::spawn(service.run());
Expand Down
8 changes: 6 additions & 2 deletions ethexe/observer/src/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod tests {
use alloy::node_bindings::Anvil;
use ethexe_ethereum::Ethereum;
use ethexe_signer::Signer;
use tokio::task;
use tokio::{sync::oneshot, task};

fn wat2wasm_with_validate(s: &str, validate: bool) -> Vec<u8> {
wabt::Wat2Wasm::new()
Expand All @@ -234,7 +234,7 @@ mod tests {
async fn test_deployment() -> Result<()> {
gear_utils::init_default_logger();

let mut anvil = Anvil::new().block_time(1).try_spawn()?;
let mut anvil = Anvil::new().try_spawn()?;
drop(anvil.child_mut().stdout.take()); //temp fix for alloy#1078

let ethereum_rpc = anvil.ws_endpoint();
Expand All @@ -253,6 +253,7 @@ mod tests {
let router_address = ethereum.router().address();
let cloned_blob_reader = blob_reader.clone();

let (send_subscription_created, receive_subscription_created) = oneshot::channel::<()>();
let handle = task::spawn(async move {
let mut observer = Observer::new(&ethereum_rpc, router_address, cloned_blob_reader)
.await
Expand All @@ -261,6 +262,8 @@ mod tests {
let observer_events = observer.events();
futures::pin_mut!(observer_events);

send_subscription_created.send(()).unwrap();

while let Some(event) = observer_events.next().await {
if matches!(event, Event::CodeLoaded { .. }) {
return Some(event);
Expand All @@ -269,6 +272,7 @@ mod tests {

None
});
receive_subscription_created.await.unwrap();

let wat = r#"
(module
Expand Down

0 comments on commit 9471bc3

Please sign in to comment.