client/authority-discovery: Publish and query on exponential interval (#7545)

* client/authority-discovery: Publish and query on exponential interval

When a node starts up publishing and querying might fail due to various
reasons, for example due to being not yet fully bootstrapped on the DHT.
Thus one should retry rather sooner than later. On the other hand, a
long running node is likely well connected and thus timely retries are
not needed. For this reasoning use an exponentially increasing interval
for `publish_interval`, `query_interval` and
`priority_group_set_interval` instead of a constant interval.

* client/authority-discovery/src/interval.rs: Add license header

* .maintain/gitlab: Ensure adder collator tests are run on CI
This commit is contained in:
Max Inden
2020-11-23 17:34:37 +01:00
committed by GitHub
parent 1871a95088
commit d692d173f2
6 changed files with 119 additions and 136 deletions
@@ -37,66 +37,6 @@ use substrate_test_runtime_client::runtime::Block;
use super::*;
#[test]
fn interval_at_with_start_now() {
let start = Instant::now();
let mut interval = interval_at(
std::time::Instant::now(),
std::time::Duration::from_secs(10),
);
futures::executor::block_on(async {
interval.next().await;
});
assert!(
Instant::now().saturating_duration_since(start) < Duration::from_secs(1),
"Expected low resolution instant interval to fire within less than a second.",
);
}
#[test]
fn interval_at_is_queuing_ticks() {
let start = Instant::now();
let interval = interval_at(start, std::time::Duration::from_millis(100));
// Let's wait for 200ms, thus 3 elements should be queued up (1st at 0ms, 2nd at 100ms, 3rd
// at 200ms).
std::thread::sleep(Duration::from_millis(200));
futures::executor::block_on(async {
interval.take(3).collect::<Vec<()>>().await;
});
// Make sure we did not wait for more than 300 ms, which would imply that `at_interval` is
// not queuing ticks.
assert!(
Instant::now().saturating_duration_since(start) < Duration::from_millis(300),
"Expect interval to /queue/ events when not polled for a while.",
);
}
#[test]
fn interval_at_with_initial_delay() {
let start = Instant::now();
let mut interval = interval_at(
std::time::Instant::now() + Duration::from_millis(100),
std::time::Duration::from_secs(10),
);
futures::executor::block_on(async {
interval.next().await;
});
assert!(
Instant::now().saturating_duration_since(start) > Duration::from_millis(100),
"Expected interval with initial delay not to fire right away.",
);
}
#[derive(Clone)]
pub(crate) struct TestApi {
pub(crate) authorities: Vec<AuthorityId>,