Skip to content

Commit bee820e

Browse files
authored
chore(libp2p-mplex): use tokio instead of async_std
ref #4449 Pull-Request: #6045.
1 parent 0f67dd7 commit bee820e

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

muxers/mplex/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tracing = { workspace = true }
2424
unsigned-varint = { workspace = true, features = ["asynchronous_codec"] }
2525

2626
[dev-dependencies]
27-
async-std = { version = "1.7.0", features = ["attributes"] }
27+
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros"] }
2828
criterion = "0.5"
2929
futures = { workspace = true }
3030
libp2p-identity = { workspace = true, features = ["rand"] }

muxers/mplex/benches/split_send_size.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@
2323
2424
use std::{pin::Pin, time::Duration};
2525

26-
use async_std::task;
2726
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
28-
use futures::{
29-
channel::oneshot,
30-
future::{join, poll_fn},
31-
prelude::*,
32-
};
27+
use futures::{channel::oneshot, future::poll_fn, prelude::*};
3328
use libp2p_core::{
3429
multiaddr::multiaddr, muxing, muxing::StreamMuxerExt, transport, transport::ListenerId,
3530
upgrade, Endpoint, Multiaddr, Transport,
@@ -38,6 +33,7 @@ use libp2p_identity as identity;
3833
use libp2p_identity::PeerId;
3934
use libp2p_mplex as mplex;
4035
use libp2p_plaintext as plaintext;
36+
use tokio::runtime::Runtime;
4137
use tracing_subscriber::EnvFilter;
4238

4339
type BenchTransport = transport::Boxed<(PeerId, muxing::StreamMuxerBox)>;
@@ -180,7 +176,10 @@ fn run(
180176
};
181177

182178
// Wait for all data to be received.
183-
task::block_on(join(sender, receiver));
179+
let rt = Runtime::new().unwrap();
180+
rt.block_on(async {
181+
tokio::join!(sender, receiver);
182+
});
184183
}
185184

186185
fn tcp_transport(split_send_size: usize) -> BenchTransport {

muxers/mplex/src/io.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,10 +1150,10 @@ const EXTRA_PENDING_FRAMES: usize = 1000;
11501150
mod tests {
11511151
use std::{collections::HashSet, num::NonZeroU8, ops::DerefMut, pin::Pin};
11521152

1153-
use async_std::task;
11541153
use asynchronous_codec::{Decoder, Encoder};
11551154
use bytes::BytesMut;
11561155
use quickcheck::*;
1156+
use tokio::runtime::Runtime;
11571157

11581158
use super::*;
11591159

@@ -1265,7 +1265,8 @@ mod tests {
12651265
};
12661266
let mut m = Multiplexed::new(conn, cfg.clone());
12671267

1268-
task::block_on(future::poll_fn(move |cx| {
1268+
let rt = Runtime::new().unwrap();
1269+
rt.block_on(future::poll_fn(move |cx| {
12691270
// Receive all inbound streams.
12701271
for i in 0..cfg.max_substreams {
12711272
match m.poll_next_stream(cx) {
@@ -1383,7 +1384,8 @@ mod tests {
13831384

13841385
// Run the test.
13851386
let mut opened = HashSet::new();
1386-
task::block_on(future::poll_fn(move |cx| {
1387+
let rt = Runtime::new().unwrap();
1388+
rt.block_on(future::poll_fn(move |cx| {
13871389
// Open a number of streams.
13881390
for _ in 0..num_streams {
13891391
let id = ready!(m.poll_open_stream(cx)).unwrap();

muxers/mplex/tests/compliance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use libp2p_mplex::Config;
22

3-
#[async_std::test]
3+
#[tokio::test]
44
async fn close_implies_flush() {
55
let (alice, bob) =
66
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<Config, _, _>().await;
77

88
libp2p_muxer_test_harness::close_implies_flush(alice, bob).await;
99
}
1010

11-
#[async_std::test]
11+
#[tokio::test]
1212
async fn read_after_close() {
1313
let (alice, bob) =
1414
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<Config, _, _>().await;

0 commit comments

Comments
 (0)