Skip to content

Commit

Permalink
refactor: mock batcher channel to unbounded channel
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeletstarkware committed Jul 4, 2024
1 parent 1c1f4c0 commit 158e523
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions crates/tests-integration/src/integration_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use starknet_mempool_types::communication::{MempoolClientImpl, MempoolRequestAnd
use starknet_mempool_types::mempool_types::ThinTransaction;
use starknet_task_executor::tokio_executor::TokioExecutor;
use tokio::runtime::Handle;
use tokio::sync::mpsc::{channel, Sender};
use tokio::sync::mpsc::{channel, unbounded_channel, UnboundedSender};
use tokio::sync::oneshot;
use tokio::task::JoinHandle;

Expand All @@ -24,7 +24,7 @@ pub struct IntegrationTestSetup {
pub gateway_client: GatewayClient,

pub batcher_handle: JoinHandle<()>,
tx_batcher: Sender<BatcherCommand>,
tx_batcher: UnboundedSender<BatcherCommand>,

pub gateway_handle: JoinHandle<()>,
pub mempool_handle: JoinHandle<()>,
Expand Down Expand Up @@ -56,7 +56,7 @@ impl IntegrationTestSetup {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;

// Build Batcher.
let (tx_batcher, rx_batcher) = channel::<BatcherCommand>(MESSAGE_QUEUE_SIZE);
let (tx_batcher, rx_batcher) = unbounded_channel::<BatcherCommand>();
let mut batcher = MockBatcher::new(rx_batcher, tx_mempool);
let batcher_handle = task_executor.spawn_with_handle(async move {
batcher.run().await;
Expand Down Expand Up @@ -88,7 +88,7 @@ impl IntegrationTestSetup {

pub async fn get_txs(&self, n_txs: usize) -> Vec<ThinTransaction> {
let (response_tx, response_rx) = oneshot::channel::<Vec<ThinTransaction>>();
self.tx_batcher.send(BatcherCommand::GetTxs(n_txs, response_tx)).await.unwrap();
self.tx_batcher.send(BatcherCommand::GetTxs(n_txs, response_tx)).unwrap();
response_rx.await.unwrap()
}
}
6 changes: 3 additions & 3 deletions crates/tests-integration/src/mock_batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use starknet_mempool_types::communication::{
MempoolClient, MempoolClientImpl, MempoolRequest, MempoolResponse,
};
use starknet_mempool_types::mempool_types::ThinTransaction;
use tokio::sync::mpsc::{Receiver, Sender};
use tokio::sync::mpsc::{Sender, UnboundedReceiver};

use crate::integration_test_utils::BatcherCommand;

pub struct MockBatcher {
rx_commands: Receiver<BatcherCommand>,
rx_commands: UnboundedReceiver<BatcherCommand>,
mempool_client: MempoolClientImpl,
}

impl MockBatcher {
pub fn new(
rx_commands: Receiver<BatcherCommand>,
rx_commands: UnboundedReceiver<BatcherCommand>,
mempool_sender: Sender<ComponentRequestAndResponseSender<MempoolRequest, MempoolResponse>>,
) -> Self {
Self { rx_commands, mempool_client: MempoolClientImpl::new(mempool_sender) }
Expand Down

0 comments on commit 158e523

Please sign in to comment.