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

Add test suite and minor refinements to the utility subsystem #1403

Merged
merged 17 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ members = [
"node/service",
"node/core/backing",
"node/subsystem",
"node/test-helpers/subsystem",
"node/test-service",

"parachain/test-parachains",
Expand Down
2 changes: 1 addition & 1 deletion node/core/backing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ bitvec = { version = "0.17.4", default-features = false, features = ["alloc"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures = { version = "0.3.5", features = ["thread-pool"] }
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
assert_matches = "1.3.0"
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = [ "test-helpers" ] }
8 changes: 4 additions & 4 deletions node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ where

/// Run this subsystem
pub async fn run(ctx: Context, keystore: KeyStorePtr, spawner: Spawner) {
<Manager<Spawner, Context>>::run(ctx, keystore, spawner).await
<Manager<Spawner, Context>>::run(ctx, keystore, spawner, None).await
}
}

Expand Down Expand Up @@ -895,13 +895,13 @@ mod tests {
}

struct TestHarness {
virtual_overseer: subsystem_test::TestSubsystemContextHandle<CandidateBackingMessage>,
virtual_overseer: polkadot_subsystem::test_helpers::TestSubsystemContextHandle<CandidateBackingMessage>,
}

fn test_harness<T: Future<Output=()>>(keystore: KeyStorePtr, test: impl FnOnce(TestHarness) -> T) {
let pool = sp_core::testing::SpawnBlockingExecutor::new();

let (context, virtual_overseer) = subsystem_test::make_subsystem_context(pool.clone());
let (context, virtual_overseer) = polkadot_subsystem::test_helpers::make_subsystem_context(pool.clone());

let subsystem = CandidateBackingSubsystem::run(context, keystore, pool.clone());

Expand Down Expand Up @@ -959,7 +959,7 @@ mod tests {

// Tests that the subsystem performs actions that are requied on startup.
async fn test_startup(
virtual_overseer: &mut subsystem_test::TestSubsystemContextHandle<CandidateBackingMessage>,
virtual_overseer: &mut polkadot_subsystem::test_helpers::TestSubsystemContextHandle<CandidateBackingMessage>,
test_state: &TestState,
) {
// Start work on some new parent.
Expand Down
1 change: 0 additions & 1 deletion node/network/bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys

[dev-dependencies]
parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
assert_matches = "1.3.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
8 changes: 4 additions & 4 deletions node/network/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ mod tests {
use assert_matches::assert_matches;

use polkadot_subsystem::messages::{StatementDistributionMessage, BitfieldDistributionMessage};
use subsystem_test::{SingleItemSink, SingleItemStream};
use polkadot_subsystem::test_helpers::{SingleItemSink, SingleItemStream};

// The subsystem's view of the network - only supports a single call to `event_stream`.
struct TestNetwork {
Expand All @@ -550,7 +550,7 @@ mod tests {
TestNetwork,
TestNetworkHandle,
) {
let (net_tx, net_rx) = subsystem_test::single_item_sink();
let (net_tx, net_rx) = polkadot_subsystem::test_helpers::single_item_sink();
let (action_tx, action_rx) = mpsc::unbounded();

(
Expand Down Expand Up @@ -631,13 +631,13 @@ mod tests {

struct TestHarness {
network_handle: TestNetworkHandle,
virtual_overseer: subsystem_test::TestSubsystemContextHandle<NetworkBridgeMessage>,
virtual_overseer: polkadot_subsystem::test_helpers::TestSubsystemContextHandle<NetworkBridgeMessage>,
}

fn test_harness<T: Future<Output=()>>(test: impl FnOnce(TestHarness) -> T) {
let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (network, network_handle) = new_test_network();
let (context, virtual_overseer) = subsystem_test::make_subsystem_context(pool);
let (context, virtual_overseer) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

let network_bridge = run_network(
network,
Expand Down
2 changes: 1 addition & 1 deletion node/network/pov-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys

[dev-dependencies]
parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
assert_matches = "1.3.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = [ "test-helpers" ] }
24 changes: 12 additions & 12 deletions node/network/pov-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov_hash;

Expand Down Expand Up @@ -700,7 +700,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov_hash;

Expand Down Expand Up @@ -778,7 +778,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
handle_network_update(
Expand Down Expand Up @@ -850,7 +850,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
// Peer A answers our request before peer B.
Expand Down Expand Up @@ -938,7 +938,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
// Peer A answers our request: right relay parent, awaited hash, wrong PoV.
Expand Down Expand Up @@ -1001,7 +1001,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
// Peer A answers our request: right relay parent, awaited hash, wrong PoV.
Expand Down Expand Up @@ -1062,7 +1062,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
// Peer A answers our request: right relay parent, awaited hash, wrong PoV.
Expand Down Expand Up @@ -1120,7 +1120,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
let max_plausibly_awaited = n_validators * 2;
Expand Down Expand Up @@ -1205,7 +1205,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
let pov_hash = make_pov(vec![1, 2, 3]).hash();
Expand Down Expand Up @@ -1267,7 +1267,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
let pov_hash = make_pov(vec![1, 2, 3]).hash();
Expand Down Expand Up @@ -1344,7 +1344,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
handle_network_update(
Expand Down Expand Up @@ -1427,7 +1427,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
handle_network_update(
Expand Down
2 changes: 1 addition & 1 deletion node/network/statement-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ indexmap = "1.4.0"

[dev-dependencies]
parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = ["test-helpers"] }
assert_matches = "1.3.0"
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
4 changes: 2 additions & 2 deletions node/network/statement-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ mod tests {
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
let peer = PeerId::random();

executor::block_on(async move {
Expand Down Expand Up @@ -1305,7 +1305,7 @@ mod tests {
].into_iter().collect();

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
let statement = {
Expand Down
10 changes: 10 additions & 0 deletions node/subsystem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ futures-timer = "3.0.2"
keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "master" }
log = "0.4.8"
parity-scale-codec = "1.3.0"
parking_lot = { version = "0.10.0", optional = true }
pin-project = "0.4.22"
polkadot-node-primitives = { path = "../primitives" }
polkadot-primitives = { path = "../../primitives" }
polkadot-statement-table = { path = "../../statement-table" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
streamunordered = "0.5.1"

[dev-dependencies]
assert_matches = "1.3.0"
async-trait = "0.1"
futures = { version = "0.3.5", features = ["thread-pool"] }
parking_lot = "0.10.0"

[features]
test-helpers = [ "parking_lot" ]
4 changes: 3 additions & 1 deletion node/subsystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use crate::messages::AllMessages;

pub mod messages;
pub mod util;
#[cfg(any(test, feature = "test-helpers"))]
pub mod test_helpers;

/// Signals sent by an overseer to a subsystem.
#[derive(PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -71,7 +73,7 @@ pub enum FromOverseer<M> {
/// * Subsystems dying when they are not expected to
/// * Subsystems not dying when they are told to die
/// * etc.
#[derive(Debug)]
#[derive(Debug, PartialEq)]
coriolinus marked this conversation as resolved.
Show resolved Hide resolved
pub struct SubsystemError;

impl From<mpsc::SendError> for SubsystemError {
Expand Down
6 changes: 6 additions & 0 deletions node/subsystem/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,10 @@ pub enum AllMessages {
AvailabilityStore(AvailabilityStoreMessage),
/// Message for the network bridge subsystem.
NetworkBridge(NetworkBridgeMessage),
/// Test message
///
/// This variant is only valid while testing, but makes the process of testing the
/// subsystem job manager much simpler.
#[cfg(test)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want #[cfg(any(test, feature = "test-helpers"))] here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No: this is only used within the internal unit tests of the job manager. If we come up with a use for it later, we can add it then. Until then, I think YAGNI is the better part of valor.

Test(String),
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

//! Utilities for testing subsystems.

use polkadot_subsystem::{SubsystemContext, FromOverseer, SubsystemResult, SubsystemError};
use polkadot_subsystem::messages::AllMessages;
use crate::{SubsystemContext, FromOverseer, SubsystemResult, SubsystemError};
use crate::messages::AllMessages;

use futures::prelude::*;
use futures::channel::mpsc;
Expand Down
Loading