From 39ed7d70d3fedcd3a6164d965f9bb9d1bbc97b48 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Thu, 21 Oct 2021 13:22:12 -0300 Subject: [PATCH] Use single thread Tokio runtime for tests (#2916) Newer versions of Tokio panic if `tokio::time::pause()` is called from a multi-thread executor, and `#[tokio::test]` defaults to a single thread runtime, so it makes sense to always use a single thread runtime in all tests. --- zebra-network/src/meta_addr/tests/prop.rs | 12 +++++++++--- .../src/peer_set/candidate_set/tests/vectors.rs | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/zebra-network/src/meta_addr/tests/prop.rs b/zebra-network/src/meta_addr/tests/prop.rs index 380c63ef..918a8696 100644 --- a/zebra-network/src/meta_addr/tests/prop.rs +++ b/zebra-network/src/meta_addr/tests/prop.rs @@ -11,7 +11,7 @@ use std::{ }; use proptest::{collection::vec, prelude::*}; -use tokio::{runtime::Runtime, time::Instant}; +use tokio::{runtime, time::Instant}; use tower::service_fn; use tracing::Span; @@ -332,7 +332,10 @@ proptest! { "there are enough changes for good test coverage", ); - let runtime = Runtime::new().expect("Failed to create Tokio runtime"); + let runtime = runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("Failed to create Tokio runtime"); let _guard = runtime.enter(); // Only put valid addresses in the address book. @@ -424,7 +427,10 @@ proptest! { "there are enough changes for good test coverage", ); - let runtime = Runtime::new().expect("Failed to create Tokio runtime"); + let runtime = runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("Failed to create Tokio runtime"); let _guard = runtime.enter(); let attempt_counts = runtime.block_on(async move { diff --git a/zebra-network/src/peer_set/candidate_set/tests/vectors.rs b/zebra-network/src/peer_set/candidate_set/tests/vectors.rs index 2c29a8f4..1daee008 100644 --- a/zebra-network/src/peer_set/candidate_set/tests/vectors.rs +++ b/zebra-network/src/peer_set/candidate_set/tests/vectors.rs @@ -8,7 +8,7 @@ use std::{ use chrono::{DateTime, Duration, Utc}; use tokio::{ - runtime::Runtime, + runtime, time::{self, Instant}, }; use tracing::Span; @@ -138,7 +138,10 @@ fn candidate_set_updates_are_rate_limited() { zebra_test::init(); - let runtime = Runtime::new().expect("Failed to create Tokio runtime"); + let runtime = runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("Failed to create Tokio runtime"); let _guard = runtime.enter(); let address_book = AddressBook::new(SocketAddr::from_str("0.0.0.0:0").unwrap(), Span::none()); @@ -179,7 +182,10 @@ fn candidate_set_updates_are_rate_limited() { /// rate limited. #[test] fn candidate_set_update_after_update_initial_is_rate_limited() { - let runtime = Runtime::new().expect("Failed to create Tokio runtime"); + let runtime = runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("Failed to create Tokio runtime"); let _guard = runtime.enter(); let address_book = AddressBook::new(SocketAddr::from_str("0.0.0.0:0").unwrap(), Span::none());