Skip to content

Commit 80d0691

Browse files
author
Solar Mithril
committed
Remove newline
Fix hanging test
1 parent 49682b0 commit 80d0691

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

crates/op-rbuilder/src/generator.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub trait PayloadBuilder: Send + Sync + Clone {
6060
pub struct BlockPayloadJobGenerator<Client, Builder> {
6161
/// The client that can interact with the chain.
6262
client: Client,
63-
6463
/// The configuration for the job generator.
6564
_config: BasicPayloadJobGeneratorConfig,
6665
/// The type responsible for building payloads.
@@ -399,7 +398,7 @@ mod tests {
399398
use alloy_eips::eip7685::Requests;
400399
use alloy_primitives::U256;
401400
use rand::thread_rng;
402-
use reth::tasks::TokioTaskExecutor;
401+
use reth::tasks::{TaskSpawner, TokioTaskExecutor};
403402
use reth_chain_state::ExecutedBlockWithTrieUpdates;
404403
use reth_node_api::NodePrimitives;
405404
use reth_optimism_payload_builder::payload::OpPayloadBuilderAttributes;
@@ -482,13 +481,15 @@ mod tests {
482481
struct MockBuilder<N> {
483482
events: Arc<Mutex<Vec<BlockEvent>>>,
484483
_marker: std::marker::PhantomData<N>,
484+
executor: TokioTaskExecutor,
485485
}
486486

487487
impl<N> MockBuilder<N> {
488488
fn new() -> Self {
489489
Self {
490490
events: Arc::new(Mutex::new(vec![])),
491491
_marker: std::marker::PhantomData,
492+
executor: TokioTaskExecutor::default(),
492493
}
493494
}
494495

@@ -550,16 +551,23 @@ mod tests {
550551
) {
551552
self.new_event(BlockEvent::Started);
552553

553-
loop {
554-
if args.cancel.is_cancelled() {
555-
self.new_event(BlockEvent::Cancelled);
556-
let _ = tx.send(Ok(()));
557-
return;
554+
let events = self.events.clone();
555+
556+
self.executor.spawn_blocking(Box::pin(async move {
557+
loop {
558+
if args.cancel.is_cancelled() {
559+
// copy of new_events to resolve the problem with self-reference on spawn
560+
let mut events = events.lock().unwrap();
561+
events.push(BlockEvent::Cancelled);
562+
let _ = tx.send(Ok(()));
563+
return;
564+
}
565+
566+
// Small sleep to prevent tight loop
567+
tokio::time::sleep(Duration::from_millis(10)).await;
558568
}
569+
}));
559570

560-
// Small sleep to prevent tight loop
561-
std::thread::sleep(Duration::from_millis(10));
562-
}
563571
}
564572
}
565573

@@ -588,7 +596,6 @@ mod tests {
588596
#[tokio::test]
589597
async fn test_payload_generator() -> eyre::Result<()> {
590598
let mut rng = thread_rng();
591-
592599
let client = MockEthProvider::default();
593600
let config = BasicPayloadJobGeneratorConfig::default();
594601
let builder = MockBuilder::<OpPrimitives>::new();

0 commit comments

Comments
 (0)