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

fix(test): Allow more time between thread CPU slices in db_init_outside_future_executor #5310

Merged
merged 1 commit into from
Oct 4, 2022
Merged
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
2 changes: 1 addition & 1 deletion zebra-test/src/mock_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const DEFAULT_PROXY_CHANNEL_SIZE: usize = 100;
///
/// Note that if a test checks that no requests are received, each check has to wait for this
/// amount of time, so this may affect the test execution time.
const DEFAULT_MAX_REQUEST_DELAY: Duration = Duration::from_millis(25);
pub const DEFAULT_MAX_REQUEST_DELAY: Duration = Duration::from_millis(25);

/// An internal type representing the item that's sent in the [`broadcast`] channel.
///
Expand Down
18 changes: 14 additions & 4 deletions zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@
//! export TMPDIR=/path/to/disk/directory
//! ```

use std::{collections::HashSet, env, fs, panic, path::PathBuf, time::Duration};
use std::{
collections::HashSet,
env, fs, panic,
path::PathBuf,
time::{Duration, Instant},
};

use color_eyre::{
eyre::{eyre, Result, WrapErr},
Expand Down Expand Up @@ -152,6 +157,13 @@ use common::{
},
};

/// The maximum amount of time that we allow the creation of a future to block the `tokio` executor.
///
/// This should be larger than the amount of time between thread time slices on a busy test VM.
///
/// This limit only applies to some tests.
pub const MAX_ASYNC_BLOCKING_TIME: Duration = zebra_test::mock_service::DEFAULT_MAX_REQUEST_DELAY;

#[test]
fn generate_no_args() -> Result<()> {
let _init_guard = zebra_test::init();
Expand Down Expand Up @@ -315,8 +327,6 @@ fn start_args() -> Result<()> {

#[tokio::test]
async fn db_init_outside_future_executor() -> Result<()> {
use std::time::{Duration, Instant};

let _init_guard = zebra_test::init();
let config = default_test_config()?;

Expand All @@ -328,7 +338,7 @@ async fn db_init_outside_future_executor() -> Result<()> {
// will wait indefinitely for blocking operation to finish once started
let block_duration = start.elapsed();
assert!(
block_duration < Duration::from_millis(5),
block_duration <= MAX_ASYNC_BLOCKING_TIME,
"futures executor was blocked longer than expected ({:?})",
block_duration,
);
Expand Down