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.
This commit is contained in:
Janito Vaqueiro Ferreira Filho 2021-10-21 13:22:12 -03:00 committed by GitHub
parent fc4a2664fd
commit 39ed7d70d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -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 {

View File

@ -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());