Skip to content

Commit

Permalink
tests: use non-failing fil_logger (#1591)
Browse files Browse the repository at this point in the history
There are tests that initialized some logger. When initializing `fil_logger`,
it would panic. Use instead `fil_logger::maybe_init()` which doesn't fail in
case there is already a logger running.
  • Loading branch information
vmx committed Apr 26, 2022
1 parent f3cde0e commit 2ed8f02
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 31 deletions.
2 changes: 1 addition & 1 deletion fil-proofs-param/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ff = "0.11.0"
blake2b_simd = "1.0.0"
bellperson = "0.18.0"
log = "0.4.7"
fil_logger = "0.1"
fil_logger = "0.1.6"
env_proxy = "0.4"
flate2 = { version = "1.0.9", features = ["rust_backend"]}
tar = "0.4.26"
Expand Down
2 changes: 1 addition & 1 deletion fil-proofs-tooling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ git2 = "0.14.2"
heim = { git = "https://github.com/heim-rs/heim", rev = "b292f15", features = ["host", "memory", "cpu"] }
async-std = "1.6"
blake2s_simd = "1.0.0"
fil_logger = "0.1"
fil_logger = "0.1.6"
log = "0.4.8"
uom = "0.32.0"
merkletree = "0.21.0"
Expand Down
2 changes: 1 addition & 1 deletion filecoin-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ff = "0.11.0"
blake2b_simd = "1.0.0"
bellperson = "0.18.0"
log = "0.4.7"
fil_logger = "0.1"
fil_logger = "0.1.6"
rayon = "1.1.0"
blake2s_simd = "1.0.0"
hex = "0.4.0"
Expand Down
18 changes: 5 additions & 13 deletions filecoin-proofs/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::BTreeMap;
use std::fs::{metadata, read_dir, remove_file, OpenOptions};
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
use std::sync::Once;

use anyhow::{ensure, Context, Error, Result};
use bellperson::groth16;
Expand Down Expand Up @@ -54,13 +53,6 @@ use filecoin_proofs::{
const ARBITRARY_POREP_ID_V1_0_0: [u8; 32] = [127; 32];
const ARBITRARY_POREP_ID_V1_1_0: [u8; 32] = [128; 32];

static INIT_LOGGER: Once = Once::new();
fn init_logger() {
INIT_LOGGER.call_once(|| {
fil_logger::init();
});
}

const TEST_SEED: [u8; 16] = [
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5,
];
Expand Down Expand Up @@ -645,7 +637,7 @@ fn run_resumable_seal<Tree: 'static + MerkleTreeTrait>(
porep_id: &[u8; 32],
api_version: ApiVersion,
) {
init_logger();
fil_logger::maybe_init();

let sector_size = SECTOR_SIZE_2_KIB;
let mut rng = XorShiftRng::from_seed(TEST_SEED);
Expand Down Expand Up @@ -1701,7 +1693,7 @@ fn create_seal<R: Rng, Tree: 'static + MerkleTreeTrait>(
porep_id: &[u8; 32],
api_version: ApiVersion,
) -> Result<(SectorId, NamedTempFile, Commitment, TempDir)> {
init_logger();
fil_logger::maybe_init();

let (mut piece_file, piece_bytes) = generate_piece_file(sector_size)?;
let sealed_sector_file = NamedTempFile::new()?;
Expand Down Expand Up @@ -1761,7 +1753,7 @@ fn create_seal_for_aggregation<R: Rng, Tree: 'static + MerkleTreeTrait>(
porep_id: &[u8; 32],
api_version: ApiVersion,
) -> Result<(SealCommitOutput, Vec<Vec<Fr>>, [u8; 32], [u8; 32])> {
init_logger();
fil_logger::maybe_init();

let (mut piece_file, _piece_bytes) = generate_piece_file(sector_size)?;
let sealed_sector_file = NamedTempFile::new()?;
Expand Down Expand Up @@ -1849,7 +1841,7 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
porep_id: &[u8; 32],
api_version: ApiVersion,
) -> Result<(SectorId, NamedTempFile, Commitment, TempDir)> {
init_logger();
fil_logger::maybe_init();

let (mut piece_file, _piece_bytes) = generate_piece_file(sector_size)?;
let sealed_sector_file = NamedTempFile::new()?;
Expand Down Expand Up @@ -2078,7 +2070,7 @@ fn create_fake_seal<R: rand::Rng, Tree: 'static + MerkleTreeTrait>(
porep_id: &[u8; 32],
api_version: ApiVersion,
) -> Result<(SectorId, NamedTempFile, Commitment, TempDir)> {
init_logger();
fil_logger::maybe_init();

let sealed_sector_file = NamedTempFile::new()?;

Expand Down
3 changes: 1 addition & 2 deletions storage-proofs-porep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ libc = "0.2"
fdlimit = "0.2.0"
fr32 = { path = "../fr32", version = "^4.0.0", default-features = false }
yastl = "0.1.2"
fil_logger = "0.1"
pairing = "0.21"
fil_logger = "0.1.6"
blstrs = "0.4.0"

[target."cfg(target_arch = \"aarch64\")".dependencies]
Expand All @@ -54,7 +54,6 @@ tempfile = "3"
rand_xorshift = "0.3.0"
criterion = "0.3.2"
glob = "0.3.0"
pretty_env_logger = "0.4.0"
filecoin-hashers = { path = "../filecoin-hashers", version = "^6.0.0", default-features = false, features = ["poseidon", "sha256", "blake2s"]}

[features]
Expand Down
15 changes: 3 additions & 12 deletions storage-proofs-porep/src/stacked/vanilla/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,23 +451,14 @@ where
mod tests {
use super::*;

use std::sync::Once;

use filecoin_hashers::poseidon::PoseidonHasher;
use storage_proofs_core::api_version::ApiVersion;

use crate::stacked::vanilla::graph::{StackedBucketGraph, EXP_DEGREE};

static INIT_LOGGER: Once = Once::new();
fn init_logger() {
INIT_LOGGER.call_once(|| {
fil_logger::init();
});
}

#[test]
fn test_read_full_range() {
init_logger();
fil_logger::maybe_init();
let nodes = 24u32;
let graph = StackedBucketGraph::<PoseidonHasher>::new_stacked(
nodes as usize,
Expand Down Expand Up @@ -520,7 +511,7 @@ mod tests {
) {
use yastl::Pool;

init_logger();
fil_logger::maybe_init();
let pool = Pool::new(3);
let nodes = 48u32;
let graph = StackedBucketGraph::<PoseidonHasher>::new_stacked(
Expand Down Expand Up @@ -571,7 +562,7 @@ mod tests {
}

fn test_read_partial_range(api_version: ApiVersion, porep_id: &[u8; 32]) {
init_logger();
fil_logger::maybe_init();
let nodes = 48u32;
let graph = StackedBucketGraph::<PoseidonHasher>::new_stacked(
nodes as usize,
Expand Down
2 changes: 1 addition & 1 deletion storage-proofs-update/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ libc = "0.2"
fdlimit = "0.2.0"
fr32 = { path = "../fr32", version = "^4.0.0", default-features = false }
yastl = "0.1.2"
fil_logger = "0.1"
fil_logger = "0.1.6"
memmap = "0.7"

[target."cfg(target_arch = \"aarch64\")".dependencies]
Expand Down

0 comments on commit 2ed8f02

Please sign in to comment.