Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Polish] - Prefer test_logger over null_logger #4545

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ fn is_candidate_block(block: &Eth1Block, period_start: u64, spec: &ChainSpec) ->
#[cfg(test)]
mod test {
use super::*;
use environment::null_logger;
use environment::test_logger;
use types::{DepositData, MinimalEthSpec, Signature};

type E = MinimalEthSpec;
Expand Down Expand Up @@ -743,7 +743,7 @@ mod test {
..Eth1Config::default()
};

let log = null_logger().unwrap();
let log = test_logger();
Eth1Chain::new(
CachingEth1Backend::new(eth1_config, log, MainnetEthSpec::default_spec()).unwrap(),
)
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/shuffling_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl BlockShufflingIds {
#[cfg(not(debug_assertions))]
#[cfg(test)]
mod test {
use task_executor::test_utils::null_logger;
use logging::test_logger;
use types::*;

use crate::test_utils::EphemeralHarnessType;
Expand All @@ -315,7 +315,7 @@ mod test {
previous: Some(shuffling_id(current_epoch - 1)),
block_root: Hash256::from_low_u64_le(0),
};
let logger = null_logger().unwrap();
let logger = test_logger();
ShufflingCache::new(TEST_CACHE_SIZE, head_shuffling_ids, logger)
}

Expand Down
27 changes: 10 additions & 17 deletions beacon_node/eth1/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
#![cfg(test)]
use environment::{Environment, EnvironmentBuilder};
use environment::{Environment, EnvironmentBuilder, test_logger};
use eth1::{Config, Eth1Endpoint, Service};
use eth1::{DepositCache, DEFAULT_CHAIN_ID};
use eth1_test_rig::{AnvilEth1Instance, Http, Middleware, Provider};
use execution_layer::http::{deposit_methods::*, HttpJsonRpc, Log};
use merkle_proof::verify_merkle_proof;
use sensitive_url::SensitiveUrl;
use slog::Logger;
use sloggers::{null::NullLoggerBuilder, Build};
use std::ops::Range;
use std::time::Duration;
use tree_hash::TreeHash;
use types::{DepositData, EthSpec, Hash256, Keypair, MainnetEthSpec, MinimalEthSpec, Signature};

const DEPOSIT_CONTRACT_TREE_DEPTH: usize = 32;

pub fn null_logger() -> Logger {
let log_builder = NullLoggerBuilder;
log_builder.build().expect("should build logger")
}

pub fn new_env() -> Environment<MinimalEthSpec> {
EnvironmentBuilder::minimal()
.multi_threaded_tokio_runtime()
.expect("should start tokio runtime")
.null_logger()
.test_logger()
.expect("should start null logger")
.build()
.expect("should build env")
Expand Down Expand Up @@ -104,7 +97,7 @@ mod eth1_cache {
#[tokio::test]
async fn simple_scenario() {
async {
let log = null_logger();
let log = test_logger();

for follow_distance in 0..3 {
let eth1 = new_anvil_instance()
Expand Down Expand Up @@ -186,7 +179,7 @@ mod eth1_cache {
#[tokio::test]
async fn big_skip() {
async {
let log = null_logger();
let log = test_logger();

let eth1 = new_anvil_instance()
.await
Expand Down Expand Up @@ -241,7 +234,7 @@ mod eth1_cache {
#[tokio::test]
async fn pruning() {
async {
let log = null_logger();
let log = test_logger();

let eth1 = new_anvil_instance()
.await
Expand Down Expand Up @@ -293,7 +286,7 @@ mod eth1_cache {
#[tokio::test]
async fn double_update() {
async {
let log = null_logger();
let log = test_logger();

let n = 16;

Expand Down Expand Up @@ -346,7 +339,7 @@ mod deposit_tree {
#[tokio::test]
async fn updating() {
async {
let log = null_logger();
let log = test_logger();

let n = 4;

Expand Down Expand Up @@ -427,7 +420,7 @@ mod deposit_tree {
#[tokio::test]
async fn double_update() {
async {
let log = null_logger();
let log = test_logger();

let n = 8;

Expand Down Expand Up @@ -689,7 +682,7 @@ mod fast {
#[tokio::test]
async fn deposit_cache_query() {
async {
let log = null_logger();
let log = test_logger();

let eth1 = new_anvil_instance()
.await
Expand Down Expand Up @@ -772,7 +765,7 @@ mod persist {
#[tokio::test]
async fn test_persist_caches() {
async {
let log = null_logger();
let log = test_logger();

let eth1 = new_anvil_instance()
.await
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/execution_layer/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::engine_api::{
auth::Auth, http::JSONRPC_VERSION, ExecutionBlock, PayloadStatusV1, PayloadStatusV1Status,
};
use bytes::Bytes;
use environment::null_logger;
use environment::test_logger;
use execution_block_generator::PoWBlock;
use handle_rpc::handle_rpc;
use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<T: EthSpec> MockServer<T> {
let ctx: Arc<Context<T>> = Arc::new(Context {
config: server_config,
jwt_key,
log: null_logger().unwrap(),
log: test_logger(),
last_echo_request: last_echo_request.clone(),
execution_block_generator: RwLock::new(execution_block_generator),
previous_request: <_>::default(),
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/genesis/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use environment::{Environment, EnvironmentBuilder};
use eth1::{Eth1Endpoint, DEFAULT_CHAIN_ID};
use eth1_test_rig::{AnvilEth1Instance, DelayThenDeposit, Middleware};
use genesis::{Eth1Config, Eth1GenesisService};
use genesis::{Eth1Config, Eth1GenesisService};
use sensitive_url::SensitiveUrl;
use state_processing::is_valid_genesis_state;
use std::time::Duration;
Expand All @@ -16,7 +16,7 @@ pub fn new_env() -> Environment<MinimalEthSpec> {
EnvironmentBuilder::minimal()
.multi_threaded_tokio_runtime()
.expect("should start tokio runtime")
.null_logger()
.test_logger()
.expect("should start null logger")
.build()
.expect("should build env")
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use beacon_chain::{
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType},
BeaconChain, StateSkipConfig, WhenSlotSkipped, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
};
use environment::null_logger;
use logging::test_logger;
use eth2::{
mixin::{RequestAccept, ResponseForkName, ResponseOptional},
reqwest::RequestBuilder,
Expand Down Expand Up @@ -229,7 +229,7 @@ impl ApiTester {
"precondition: justification"
);

let log = null_logger().unwrap();
let log = test_logger();

let ApiServer {
server,
Expand Down Expand Up @@ -315,7 +315,7 @@ impl ApiTester {

let chain = harness.chain.clone();

let log = null_logger().unwrap();
let log = test_logger();

let ApiServer {
server,
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_metrics/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use beacon_chain::test_utils::EphemeralHarnessType;
use environment::null_logger;
use environment::test_logger;
use http_metrics::Config;
use reqwest::header::HeaderValue;
use reqwest::StatusCode;
Expand All @@ -13,7 +13,7 @@ type Context = http_metrics::Context<EphemeralHarnessType<MainnetEthSpec>>;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn returns_200_ok() {
async {
let log = null_logger().unwrap();
let log = test_logger();

let context = Arc::new(Context {
config: Config {
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/network/src/network_beacon_processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use beacon_processor::{
GossipAggregatePackage, GossipAttestationPackage, Work, WorkEvent as BeaconWorkEvent,
MAX_SCHEDULED_WORK_QUEUE_LEN, MAX_WORK_EVENT_QUEUE_LEN,
};
use environment::null_logger;
use logging::test_logger;
use lighthouse_network::{
rpc::{BlocksByRangeRequest, BlocksByRootRequest, LightClientBootstrapRequest, StatusMessage},
Client, MessageId, NetworkGlobals, PeerId, PeerRequestId,
Expand Down Expand Up @@ -550,7 +550,7 @@ impl<E: EthSpec> NetworkBeaconProcessor<TestBeaconChainType<E>> {
let (network_tx, _network_rx) = mpsc::unbounded_channel();
let (sync_tx, _sync_rx) = mpsc::unbounded_channel();
let (reprocess_tx, _reprocess_rx) = mpsc::channel(MAX_SCHEDULED_WORK_QUEUE_LEN);
let log = null_logger().unwrap();
let log = test_logger();
let harness: BeaconChainHarness<TestBeaconChainType<E>> =
BeaconChainHarness::builder(E::default())
.spec(E::default_spec())
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn build_node<E: EthSpec>(env: &mut Environment<E>) -> LocalBeaconNode<E> {
#[test]
fn http_server_genesis_state() {
let mut env = env_builder()
.null_logger()
.test_logger()
//.async_logger("debug", None)
.expect("should build env logger")
.multi_threaded_tokio_runtime()
Expand Down
4 changes: 2 additions & 2 deletions lcli/src/transition_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use beacon_chain::{
};
use clap::ArgMatches;
use clap_utils::{parse_optional, parse_required};
use environment::{null_logger, Environment};
use environment::{Environment, test_logger};
use eth2::{
types::{BlockId, StateId},
BeaconNodeHttpClient, SensitiveUrl, Timeouts,
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn run<T: EthSpec>(
let store = HotColdDB::open_ephemeral(
<_>::default(),
spec.clone(),
null_logger().map_err(|e| format!("Failed to create null_logger: {:?}", e))?,
test_logger(),
)
.map_err(|e| format!("Failed to create ephemeral store: {:?}", e))?;
let store = Arc::new(store);
Expand Down
6 changes: 3 additions & 3 deletions lighthouse/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use {
#[cfg(not(target_family = "unix"))]
use {futures::channel::oneshot, std::cell::RefCell};

pub use task_executor::test_utils::null_logger;
pub use logging::test_logger;

const LOG_CHANNEL_SIZE: usize = 2048;
const SSE_LOG_CHANNEL_SIZE: usize = 2048;
Expand Down Expand Up @@ -185,8 +185,8 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
}

/// Specifies that all logs should be sent to `null` (i.e., ignored).
pub fn null_logger(mut self) -> Result<Self, String> {
self.log = Some(null_logger()?);
pub fn test_logger(mut self) -> Result<Self, String> {
self.log = Some(test_logger());
Ok(self)
}

Expand Down
2 changes: 1 addition & 1 deletion lighthouse/environment/tests/environment_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn builder() -> EnvironmentBuilder<MainnetEthSpec> {
EnvironmentBuilder::mainnet()
.multi_threaded_tokio_runtime()
.expect("should set runtime")
.null_logger()
.test_logger()
.expect("should set logger")
}

Expand Down
3 changes: 2 additions & 1 deletion testing/web3signer_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ mod tests {

impl ValidatorStoreRig {
pub async fn new(validator_definitions: Vec<ValidatorDefinition>, spec: ChainSpec) -> Self {
let log = environment::null_logger().unwrap();
let log = logging::test_logger();

let validator_dir = TempDir::new().unwrap();

let validator_definitions = ValidatorDefinitions::from(validator_definitions);
Expand Down
4 changes: 2 additions & 2 deletions validator_client/src/doppelganger_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ impl DoppelgangerService {
#[cfg(test)]
mod test {
use super::*;
use environment::null_logger;
use logging::test_logger;
use futures::executor::block_on;
use slot_clock::TestingSlotClock;
use std::collections::HashSet;
Expand Down Expand Up @@ -717,7 +717,7 @@ mod test {
fn build(self) -> TestScenario {
let mut rng = XorShiftRng::from_seed([42; 16]);
let slot_clock = TestingSlotClock::new(Slot::new(0), GENESIS_TIME, SLOT_DURATION);
let log = null_logger().unwrap();
let log = test_logger();

TestScenario {
validators: (0..self.validator_count)
Expand Down
Loading