Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add make_buffered_subsystem_context in subsystem-test-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tdimitrov committed Nov 14, 2022
1 parent 4d16f95 commit a7f5248
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions node/core/dispute-coordinator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ use polkadot_node_subsystem::{
messages::{AllMessages, BlockDescription, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
};
use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle};
use polkadot_node_subsystem_test_helpers::{
make_buffered_subsystem_context, TestSubsystemContextHandle,
};
use polkadot_primitives::v2::{
ApprovalVote, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
CandidateReceipt, CoreIndex, DisputeStatement, GroupIndex, Hash, HeadData, Header, IndexedVec,
Expand Down Expand Up @@ -523,7 +525,7 @@ impl TestState {
F: FnOnce(TestState, VirtualOverseer) -> BoxFuture<'static, TestState>,
{
self.known_session = None;
let (ctx, ctx_handle) = make_subsystem_context(TaskExecutor::new());
let (ctx, ctx_handle) = make_buffered_subsystem_context(TaskExecutor::new(), 1);
let subsystem = DisputeCoordinatorSubsystem::new(
self.db.clone(),
self.config.clone(),
Expand Down
15 changes: 13 additions & 2 deletions node/subsystem-test-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,22 @@ impl<M> TestSubsystemContextHandle<M> {
}
}

/// Make a test subsystem context.
/// Make a test subsystem context with `buffer_size == 0`. This is used by most
/// of the tests.
pub fn make_subsystem_context<M, S>(
spawner: S,
) -> (TestSubsystemContext<M, SpawnGlue<S>>, TestSubsystemContextHandle<M>) {
let (overseer_tx, overseer_rx) = mpsc::channel(1);
make_buffered_subsystem_context(spawner, 0)
}

/// Make a test subsystem context with buffered overseer channel. Some tests (e.g.
/// `dispute-coordinator`) create too many parallel operations and deadlock unless
/// the channel is buffered. Usually `buffer_size=1` is enough.
pub fn make_buffered_subsystem_context<M, S>(
spawner: S,
buffer_size: usize,
) -> (TestSubsystemContext<M, SpawnGlue<S>>, TestSubsystemContextHandle<M>) {
let (overseer_tx, overseer_rx) = mpsc::channel(buffer_size);
let (all_messages_tx, all_messages_rx) = mpsc::unbounded();

(
Expand Down

0 comments on commit a7f5248

Please sign in to comment.