Unverified Commit bf7ccb84 authored by Fedor Sakharov's avatar Fedor Sakharov Committed by GitHub
Browse files

use own timeout in tests instead of smol-timeout (#1618)

parent 61f306dc
Pipeline #104421 passed with stages
in 27 minutes and 54 seconds
...@@ -4371,18 +4371,18 @@ dependencies = [ ...@@ -4371,18 +4371,18 @@ dependencies = [
[[package]] [[package]]
name = "pin-project" name = "pin-project"
version = "0.4.22" version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17" checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa"
dependencies = [ dependencies = [
"pin-project-internal", "pin-project-internal",
] ]
[[package]] [[package]]
name = "pin-project-internal" name = "pin-project-internal"
version = "0.4.22" version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f"
dependencies = [ dependencies = [
"proc-macro2 1.0.18", "proc-macro2 1.0.18",
"quote 1.0.7", "quote 1.0.7",
...@@ -4448,7 +4448,6 @@ dependencies = [ ...@@ -4448,7 +4448,6 @@ dependencies = [
"polkadot-primitives", "polkadot-primitives",
"sc-network", "sc-network",
"smol 0.3.3", "smol 0.3.3",
"smol-timeout",
"sp-core", "sp-core",
"streamunordered", "streamunordered",
] ]
...@@ -4474,7 +4473,6 @@ dependencies = [ ...@@ -4474,7 +4473,6 @@ dependencies = [
"polkadot-primitives", "polkadot-primitives",
"sc-keystore", "sc-keystore",
"smallvec 1.4.1", "smallvec 1.4.1",
"smol-timeout",
"sp-core", "sp-core",
"sp-keyring", "sp-keyring",
"streamunordered", "streamunordered",
...@@ -7600,16 +7598,6 @@ dependencies = [ ...@@ -7600,16 +7598,6 @@ dependencies = [
"num_cpus", "num_cpus",
] ]
[[package]]
name = "smol-timeout"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "024818c1f00b80e8171ddcfcee33860134293aa3aced60c9cbd7a5a2d41db392"
dependencies = [
"pin-project",
"smol 0.1.18",
]
[[package]] [[package]]
name = "snow" name = "snow"
version = "0.7.1" version = "0.7.1"
......
...@@ -25,7 +25,6 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", ...@@ -25,7 +25,6 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master",
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
parking_lot = "0.11.0" parking_lot = "0.11.0"
futures-timer = "3.0.2" futures-timer = "3.0.2"
smol-timeout = "0.1.0"
env_logger = "0.7.1" env_logger = "0.7.1"
assert_matches = "1.3.0" assert_matches = "1.3.0"
smallvec = "1" smallvec = "1"
...@@ -22,13 +22,12 @@ use polkadot_primitives::v1::{ ...@@ -22,13 +22,12 @@ use polkadot_primitives::v1::{
GroupRotationInfo, HeadData, PersistedValidationData, OccupiedCore, GroupRotationInfo, HeadData, PersistedValidationData, OccupiedCore,
PoV, ScheduledCore, ValidatorPair, PoV, ScheduledCore, ValidatorPair,
}; };
use polkadot_subsystem_testhelpers as test_helpers; use polkadot_subsystem_testhelpers::{self as test_helpers, TimeoutExt};
use polkadot_node_network_protocol::ObservedRole; use polkadot_node_network_protocol::ObservedRole;
use futures::{executor, future, Future}; use futures::{executor, future, Future};
use futures_timer::Delay; use futures_timer::Delay;
use smallvec::smallvec; use smallvec::smallvec;
use smol_timeout::TimeoutExt;
use std::time::Duration; use std::time::Duration;
macro_rules! view { macro_rules! view {
......
...@@ -24,6 +24,5 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } ...@@ -24,6 +24,5 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
parking_lot = "0.11.0" parking_lot = "0.11.0"
maplit = "1.0.2" maplit = "1.0.2"
smol = "0.3.3" smol = "0.3.3"
smol-timeout = "0.1.0"
env_logger = "0.7.1" env_logger = "0.7.1"
assert_matches = "1.3.0" assert_matches = "1.3.0"
...@@ -611,8 +611,7 @@ mod test { ...@@ -611,8 +611,7 @@ mod test {
use futures::executor; use futures::executor;
use maplit::hashmap; use maplit::hashmap;
use polkadot_primitives::v1::{Signed, ValidatorPair, AvailabilityBitfield}; use polkadot_primitives::v1::{Signed, ValidatorPair, AvailabilityBitfield};
use polkadot_node_subsystem_test_helpers::make_subsystem_context; use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TimeoutExt};
use smol_timeout::TimeoutExt;
use sp_core::crypto::Pair; use sp_core::crypto::Pair;
use std::time::Duration; use std::time::Duration;
use assert_matches::assert_matches; use assert_matches::assert_matches;
......
...@@ -13,7 +13,7 @@ futures-timer = "3.0.2" ...@@ -13,7 +13,7 @@ futures-timer = "3.0.2"
log = "0.4.8" log = "0.4.8"
parity-scale-codec = "1.3.4" parity-scale-codec = "1.3.4"
parking_lot = "0.10.0" parking_lot = "0.10.0"
pin-project = "0.4.22" pin-project = "0.4.23"
polkadot-node-primitives = { path = "../primitives" } polkadot-node-primitives = { path = "../primitives" }
polkadot-node-subsystem = { path = "../subsystem" } polkadot-node-subsystem = { path = "../subsystem" }
polkadot-primitives = { path = "../../primitives" } polkadot-primitives = { path = "../../primitives" }
......
...@@ -24,6 +24,7 @@ use futures::poll; ...@@ -24,6 +24,7 @@ use futures::poll;
use futures::prelude::*; use futures::prelude::*;
use futures_timer::Delay; use futures_timer::Delay;
use parking_lot::Mutex; use parking_lot::Mutex;
use pin_project::pin_project;
use sp_core::{testing::TaskExecutor, traits::SpawnNamed}; use sp_core::{testing::TaskExecutor, traits::SpawnNamed};
use std::convert::Infallible; use std::convert::Infallible;
...@@ -286,3 +287,45 @@ pub fn subsystem_test_harness<M, OverseerFactory, Overseer, TestFactory, Test>( ...@@ -286,3 +287,45 @@ pub fn subsystem_test_harness<M, OverseerFactory, Overseer, TestFactory, Test>(
} }
}); });
} }
/// A future that wraps another future with a `Delay` allowing for time-limited futures.
#[pin_project]
pub struct Timeout<F: Future> {
#[pin]
future: F,
#[pin]
delay: Delay,
}
/// Extends `Future` to allow time-limited futures.
pub trait TimeoutExt: Future {
fn timeout(self, duration: Duration) -> Timeout<Self>
where
Self: Sized,
{
Timeout {
future: self,
delay: Delay::new(duration),
}
}
}
impl<F: Future> TimeoutExt for F {}
impl<F: Future> Future for Timeout<F> {
type Output = Option<F::Output>;
fn poll(self: Pin<&mut Self>, ctx: &mut Context) -> Poll<Self::Output> {
let this = self.project();
if this.delay.poll(ctx).is_ready() {
return Poll::Ready(None);
}
if let Poll::Ready(output) = this.future.poll(ctx) {
return Poll::Ready(Some(output));
}
Poll::Pending
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment