mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-02 20:34:27 +00:00
Fix tests
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2872,6 +2872,7 @@ dependencies = [
|
|||||||
"error-chain",
|
"error-chain",
|
||||||
"eth2-libp2p",
|
"eth2-libp2p",
|
||||||
"eth2_ssz",
|
"eth2_ssz",
|
||||||
|
"exit-future",
|
||||||
"fnv",
|
"fnv",
|
||||||
"futures 0.3.5",
|
"futures 0.3.5",
|
||||||
"genesis",
|
"genesis",
|
||||||
|
|||||||
@@ -86,7 +86,12 @@ pub fn build_libp2p_instance(
|
|||||||
let port = unused_port("tcp").unwrap();
|
let port = unused_port("tcp").unwrap();
|
||||||
let config = build_config(port, boot_nodes, secret_key);
|
let config = build_config(port, boot_nodes, secret_key);
|
||||||
// launch libp2p service
|
// launch libp2p service
|
||||||
LibP2PService::new(&config, EnrForkId::default(), &log)
|
LibP2PService::new(
|
||||||
|
tokio::runtime::Handle::current(),
|
||||||
|
&config,
|
||||||
|
EnrForkId::default(),
|
||||||
|
&log,
|
||||||
|
)
|
||||||
.expect("should build libp2p instance")
|
.expect("should build libp2p instance")
|
||||||
.1
|
.1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,12 @@ async fn test_secio_noise_fallback() {
|
|||||||
|
|
||||||
let port = common::unused_port("tcp").unwrap();
|
let port = common::unused_port("tcp").unwrap();
|
||||||
let noisy_config = common::build_config(port, vec![], None);
|
let noisy_config = common::build_config(port, vec![], None);
|
||||||
let mut noisy_node = Service::new(&noisy_config, EnrForkId::default(), &log)
|
let mut noisy_node = Service::new(
|
||||||
|
tokio::runtime::Handle::current(),
|
||||||
|
&noisy_config,
|
||||||
|
EnrForkId::default(),
|
||||||
|
&log,
|
||||||
|
)
|
||||||
.expect("should build a libp2p instance")
|
.expect("should build a libp2p instance")
|
||||||
.1;
|
.1;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ genesis = { path = "../genesis" }
|
|||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
matches = "0.1.8"
|
matches = "0.1.8"
|
||||||
tempfile = "3.1.0"
|
tempfile = "3.1.0"
|
||||||
|
exit-future = "0.2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
beacon_chain = { path = "../beacon_chain" }
|
beacon_chain = { path = "../beacon_chain" }
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ mod tests {
|
|||||||
let enrs = vec![enr1, enr2];
|
let enrs = vec![enr1, enr2];
|
||||||
|
|
||||||
let runtime = Runtime::new().unwrap();
|
let runtime = Runtime::new().unwrap();
|
||||||
let handle = runtime.handle().clone();
|
|
||||||
|
let (signal, exit) = exit_future::signal();
|
||||||
|
let executor = environment::TaskExecutor::new(runtime.handle().clone(), exit, log.clone());
|
||||||
|
|
||||||
let mut config = NetworkConfig::default();
|
let mut config = NetworkConfig::default();
|
||||||
config.libp2p_port = 21212;
|
config.libp2p_port = 21212;
|
||||||
@@ -42,8 +44,9 @@ mod tests {
|
|||||||
// Create a new network service which implicitly gets dropped at the
|
// Create a new network service which implicitly gets dropped at the
|
||||||
// end of the block.
|
// end of the block.
|
||||||
|
|
||||||
let _ =
|
let _ = NetworkService::start(beacon_chain.clone(), &config, executor, log.clone())
|
||||||
NetworkService::start(beacon_chain.clone(), &config, &handle, log.clone()).unwrap();
|
.unwrap();
|
||||||
|
drop(signal);
|
||||||
});
|
});
|
||||||
runtime.shutdown_timeout(tokio::time::Duration::from_millis(300));
|
runtime.shutdown_timeout(tokio::time::Duration::from_millis(300));
|
||||||
|
|
||||||
|
|||||||
@@ -237,6 +237,12 @@ pub struct TaskExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TaskExecutor {
|
impl TaskExecutor {
|
||||||
|
/// Create a new task executor.
|
||||||
|
///
|
||||||
|
/// Note: this is mainly useful in testing.
|
||||||
|
pub fn new(handle: Handle, exit: exit_future::Exit, log: slog::Logger) -> Self {
|
||||||
|
Self { handle, exit, log }
|
||||||
|
}
|
||||||
/// Spawn a future on the tokio runtime wrapped in an exit_future `Exit`. The task is canceled
|
/// Spawn a future on the tokio runtime wrapped in an exit_future `Exit`. The task is canceled
|
||||||
/// when the corresponding exit_future `Signal` is fired/dropped.
|
/// when the corresponding exit_future `Signal` is fired/dropped.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -540,6 +540,7 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use futures::future::FutureExt;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
|
||||||
/// This test is to ensure that a `tokio_timer::Delay` with an instant in the past will still
|
/// This test is to ensure that a `tokio_timer::Delay` with an instant in the past will still
|
||||||
|
|||||||
Reference in New Issue
Block a user