Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Jul 19, 2021
1 parent 9f9c184 commit f54a086
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions beacon_node/network/src/subnet_service/sync_subnets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ impl<T: BeaconChainTypes> SyncCommitteeService<T> {
.collect();

if !discovery_subnets.is_empty() {
trace!(self.log, "Making a discovery query");
self.events
.push_back(SubnetServiceMessage::DiscoverPeers(discovery_subnets));
}
Expand Down Expand Up @@ -252,6 +253,7 @@ impl<T: BeaconChainTypes> SyncCommitteeService<T> {

let slots_per_epoch = T::EthSpec::slots_per_epoch();
let until_slot = exact_subnet.until_epoch.end_slot(slots_per_epoch);
dbg!(&until_slot);
// Calculate the duration to the unsubscription event.
let expected_end_subscription_duration = if current_slot >= until_slot {
warn!(
Expand Down
26 changes: 18 additions & 8 deletions beacon_node/network/src/subnet_service/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use genesis::{generate_deterministic_keypairs, interop_genesis_state};
use lazy_static::lazy_static;
use matches::assert_matches;
use slog::Logger;
use sloggers::{null::NullLoggerBuilder, Build};
use slog::{o, Drain};
use slot_clock::{SlotClock, SystemTimeSlotClock};
use std::sync::Arc;
use std::time::{Duration, SystemTime};
Expand Down Expand Up @@ -41,7 +41,7 @@ impl TestBeaconChain {

let keypairs = generate_deterministic_keypairs(1);

let log = get_logger();
let log = get_logger(false);
let store =
HotColdDB::open_ephemeral(StoreConfig::default(), spec.clone(), log.clone()).unwrap();

Expand Down Expand Up @@ -80,16 +80,25 @@ pub fn recent_genesis_time() -> u64 {
.as_secs()
}

fn get_logger() -> Logger {
NullLoggerBuilder.build().expect("logger should build")
fn get_logger(enabled: bool) -> Logger {
let level = slog::Level::Trace;
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::FullFormat::new(decorator).build().fuse();
let drain = slog_async::Async::new(drain).build().fuse();

if enabled {
slog::Logger::root(drain.filter_level(level).fuse(), o!())
} else {
slog::Logger::root(drain.filter(|_| false).fuse(), o!())
}
}

lazy_static! {
static ref CHAIN: TestBeaconChain = TestBeaconChain::new_with_system_clock();
}

fn get_attestation_service() -> AttestationService<TestBeaconChainType> {
let log = get_logger();
let log = get_logger(false);
let config = NetworkConfig::default();

let beacon_chain = CHAIN.chain.clone();
Expand All @@ -98,7 +107,7 @@ fn get_attestation_service() -> AttestationService<TestBeaconChainType> {
}

fn get_sync_committee_service() -> SyncCommitteeService<TestBeaconChainType> {
let log = get_logger();
let log = get_logger(true);
let config = NetworkConfig::default();

let beacon_chain = CHAIN.chain.clone();
Expand Down Expand Up @@ -456,7 +465,7 @@ mod sync_committee_service {
async fn subscribe_and_unsubscribe() {
// subscription config
let validator_index = 1;
let until_epoch = Epoch::new(0);
let until_epoch = Epoch::new(1);
let sync_committee_indices = vec![1];

// create the attestation service and subscriptions
Expand All @@ -480,10 +489,11 @@ mod sync_committee_service {
let subnet_id = subnet_ids.iter().next().unwrap();

// Note: the unsubscription event takes a full epoch (8 * 0.2 secs = 1.6 secs)
dbg!(MinimalEthSpec::slots_per_epoch());
let events = get_events(
&mut sync_committee_service,
Some(5),
MinimalEthSpec::slots_per_epoch() as u32,
(MinimalEthSpec::slots_per_epoch() * 2) as u32,
)
.await;
assert_eq!(
Expand Down

0 comments on commit f54a086

Please sign in to comment.