fix(test): Improve test reliability and performance (#4869)
* Improve UnreadyService documentation * Limit proptest cases to speed up a slow test * Skip the delete old databases test when there is no network
This commit is contained in:
parent
9441a1f66c
commit
69751e964c
|
@ -1,5 +1,6 @@
|
||||||
// Adapted from tower-balance
|
/// Services that are busy or newly created.
|
||||||
|
///
|
||||||
|
/// Adapted from tower-balance.
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
|
@ -21,11 +22,18 @@ mod tests;
|
||||||
#[pin_project]
|
#[pin_project]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct UnreadyService<K, S, Req> {
|
pub(super) struct UnreadyService<K, S, Req> {
|
||||||
|
/// The key used to lookup `service`.
|
||||||
pub(super) key: Option<K>,
|
pub(super) key: Option<K>,
|
||||||
|
|
||||||
|
/// A oneshot used to cancel the request the `service` is currently working on, if any.
|
||||||
#[pin]
|
#[pin]
|
||||||
pub(super) cancel: oneshot::Receiver<CancelClientWork>,
|
pub(super) cancel: oneshot::Receiver<CancelClientWork>,
|
||||||
|
|
||||||
|
/// The `service` that is busy (or newly created).
|
||||||
pub(super) service: Option<S>,
|
pub(super) service: Option<S>,
|
||||||
|
|
||||||
|
/// Dropping `service` might drop a request.
|
||||||
|
/// This [`PhantomData`] tells the Rust compiler to do a drop check for `Req`.
|
||||||
pub(super) _req: PhantomData<Req>,
|
pub(super) _req: PhantomData<Req>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Tests for trusted preallocation during deserialization.
|
//! Tests for trusted preallocation during deserialization.
|
||||||
|
|
||||||
use std::convert::TryInto;
|
use std::env;
|
||||||
|
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
@ -20,7 +20,16 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The number of test cases to use for expensive proptests.
|
||||||
|
const DEFAULT_PROPTEST_CASES: u32 = 8;
|
||||||
|
|
||||||
proptest! {
|
proptest! {
|
||||||
|
// Set the PROPTEST_CASES env var to override this default.
|
||||||
|
#![proptest_config(proptest::test_runner::Config::with_cases(env::var("PROPTEST_CASES")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.parse().ok())
|
||||||
|
.unwrap_or(DEFAULT_PROPTEST_CASES)))]
|
||||||
|
|
||||||
/// Confirm that each InventoryHash takes the expected size in bytes when serialized.
|
/// Confirm that each InventoryHash takes the expected size in bytes when serialized.
|
||||||
#[test]
|
#[test]
|
||||||
fn inv_hash_size_is_correct(inv in any::<InventoryHash>()) {
|
fn inv_hash_size_is_correct(inv in any::<InventoryHash>()) {
|
||||||
|
@ -71,6 +80,12 @@ proptest! {
|
||||||
}
|
}
|
||||||
|
|
||||||
proptest! {
|
proptest! {
|
||||||
|
// Set the PROPTEST_CASES env var to override this default.
|
||||||
|
#![proptest_config(proptest::test_runner::Config::with_cases(env::var("PROPTEST_CASES")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.parse().ok())
|
||||||
|
.unwrap_or(DEFAULT_PROPTEST_CASES)))]
|
||||||
|
|
||||||
/// Confirm that each AddrV1 takes exactly ADDR_V1_SIZE bytes when serialized.
|
/// Confirm that each AddrV1 takes exactly ADDR_V1_SIZE bytes when serialized.
|
||||||
/// This verifies that our calculated `TrustedPreallocate::max_allocation()` is indeed an upper bound.
|
/// This verifies that our calculated `TrustedPreallocate::max_allocation()` is indeed an upper bound.
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -122,6 +137,12 @@ proptest! {
|
||||||
}
|
}
|
||||||
|
|
||||||
proptest! {
|
proptest! {
|
||||||
|
// Set the PROPTEST_CASES env var to override this default.
|
||||||
|
#![proptest_config(proptest::test_runner::Config::with_cases(env::var("PROPTEST_CASES")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.parse().ok())
|
||||||
|
.unwrap_or(DEFAULT_PROPTEST_CASES)))]
|
||||||
|
|
||||||
/// Confirm that each AddrV2 takes at least ADDR_V2_MIN_SIZE bytes when serialized.
|
/// Confirm that each AddrV2 takes at least ADDR_V2_MIN_SIZE bytes when serialized.
|
||||||
/// This verifies that our calculated `TrustedPreallocate::max_allocation()` is indeed an upper bound.
|
/// This verifies that our calculated `TrustedPreallocate::max_allocation()` is indeed an upper bound.
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1811,6 +1811,15 @@ async fn delete_old_databases() -> Result<()> {
|
||||||
|
|
||||||
zebra_test::init();
|
zebra_test::init();
|
||||||
|
|
||||||
|
// Skip this test because it can be very slow without a network.
|
||||||
|
//
|
||||||
|
// The delete databases task is launched last during startup, after network setup.
|
||||||
|
// If there is no network, network setup can take a long time to timeout,
|
||||||
|
// so the task takes a long time to launch, slowing down this test.
|
||||||
|
if zebra_test::net::zebra_skip_network_tests() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let mut config = default_test_config()?;
|
let mut config = default_test_config()?;
|
||||||
let run_dir = testdir()?;
|
let run_dir = testdir()?;
|
||||||
let cache_dir = run_dir.path().join("state");
|
let cache_dir = run_dir.path().join("state");
|
||||||
|
|
Loading…
Reference in New Issue