Skip to content

Commit 13b9ea2

Browse files
authored
chore: refactor dcutr and gossipsub tests to use tokio instead
ref #4449 Refactored dcutr and gossipsub tests to use `tokio` instead of `async-std`. Pull-Request: #5662.
1 parent 059742f commit 13b9ea2

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocols/dcutr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ lru = "0.12.3"
2727
futures-bounded = { workspace = true }
2828

2929
[dev-dependencies]
30-
async-std = { version = "1.12.0", features = ["attributes"] }
3130
clap = { version = "4.5.6", features = ["derive"] }
3231
libp2p-dns = { workspace = true, features = ["async-std"] }
3332
libp2p-identify = { workspace = true }
@@ -41,6 +40,7 @@ libp2p-tcp = { workspace = true, features = ["async-io"] }
4140
libp2p-yamux = { workspace = true }
4241
rand = "0.8"
4342
tracing-subscriber = { workspace = true, features = ["env-filter"] }
43+
tokio = { workspace = true, features = ["rt", "macros"] }
4444

4545
# Passing arguments to the docsrs builder in order to properly document cfg's.
4646
# More information: https://docs.rs/about/builds#cross-compiling

protocols/dcutr/tests/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use libp2p_swarm_test::SwarmExt as _;
3232
use std::time::Duration;
3333
use tracing_subscriber::EnvFilter;
3434

35-
#[async_std::test]
35+
#[tokio::test]
3636
async fn connect() {
3737
let _ = tracing_subscriber::fmt()
3838
.with_env_filter(EnvFilter::from_default_env())
@@ -53,7 +53,7 @@ async fn connect() {
5353
let relay_peer_id = *relay.local_peer_id();
5454
let dst_peer_id = *dst.local_peer_id();
5555

56-
async_std::task::spawn(relay.loop_on_next());
56+
tokio::spawn(relay.loop_on_next());
5757

5858
let dst_relayed_addr = relay_tcp_addr
5959
.with(Protocol::P2p(relay_peer_id))
@@ -68,7 +68,7 @@ async fn connect() {
6868
false, // No renewal.
6969
)
7070
.await;
71-
async_std::task::spawn(dst.loop_on_next());
71+
tokio::spawn(dst.loop_on_next());
7272

7373
src.dial_and_wait(dst_relayed_addr.clone()).await;
7474

protocols/gossipsub/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ tracing = { workspace = true }
4141
prometheus-client = { workspace = true }
4242

4343
[dev-dependencies]
44-
async-std = { version = "1.6.3", features = ["unstable"] }
4544
hex = "0.4.2"
4645
libp2p-core = { workspace = true }
4746
libp2p-yamux = { workspace = true }
4847
libp2p-noise = { workspace = true }
4948
libp2p-swarm-test = { path = "../../swarm-test" }
5049
quickcheck = { workspace = true }
5150
tracing-subscriber = { workspace = true, features = ["env-filter"] }
51+
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "time"] }
5252

5353
# Passing arguments to the docsrs builder in order to properly document cfg's.
5454
# More information: https://docs.rs/about/builds#cross-compiling

protocols/gossipsub/src/behaviour/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
use super::*;
2424
use crate::subscription_filter::WhitelistSubscriptionFilter;
2525
use crate::{config::ConfigBuilder, types::Rpc, IdentTopic as Topic};
26-
use async_std::net::Ipv4Addr;
2726
use byteorder::{BigEndian, ByteOrder};
2827
use libp2p_core::ConnectedPoint;
2928
use rand::Rng;
29+
use std::net::Ipv4Addr;
3030
use std::thread::sleep;
3131

3232
#[derive(Default, Debug)]

protocols/gossipsub/tests/smoke.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

21-
use async_std::prelude::FutureExt;
2221
use futures::stream::{FuturesUnordered, SelectAll};
2322
use futures::StreamExt;
2423
use libp2p_gossipsub as gossipsub;
@@ -28,7 +27,9 @@ use libp2p_swarm_test::SwarmExt as _;
2827
use quickcheck::{QuickCheck, TestResult};
2928
use rand::{seq::SliceRandom, SeedableRng};
3029
use std::{task::Poll, time::Duration};
30+
use tokio::{runtime::Runtime, time};
3131
use tracing_subscriber::EnvFilter;
32+
3233
struct Graph {
3334
nodes: SelectAll<Swarm<gossipsub::Behaviour>>,
3435
}
@@ -84,7 +85,7 @@ impl Graph {
8485
}
8586
};
8687

87-
match condition.timeout(Duration::from_secs(10)).await {
88+
match time::timeout(Duration::from_secs(10), condition).await {
8889
Ok(()) => true,
8990
Err(_) => false,
9091
}
@@ -98,7 +99,7 @@ impl Graph {
9899
Poll::Pending => return Poll::Ready(()),
99100
}
100101
});
101-
fut.timeout(Duration::from_secs(10)).await.unwrap();
102+
time::timeout(Duration::from_secs(10), fut).await.unwrap();
102103
}
103104
}
104105

@@ -139,7 +140,9 @@ fn multi_hop_propagation() {
139140

140141
tracing::debug!(number_of_nodes=%num_nodes, seed=%seed);
141142

142-
async_std::task::block_on(async move {
143+
let rt = Runtime::new().unwrap();
144+
145+
rt.block_on(async move {
143146
let mut graph = Graph::new_connected(num_nodes as usize, seed).await;
144147
let number_nodes = graph.nodes.len();
145148

0 commit comments

Comments
 (0)