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

chore: use tokio instead of async-std #5828

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tracing = { workspace = true }
unsigned-varint = { workspace = true }

[dev-dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }
tokio = { workspace = true, features = ["rt", "macros"] }
libp2p-mplex = { path = "../muxers/mplex" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing.
libp2p-noise = { path = "../transports/noise" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing.
multihash = { workspace = true, features = ["arb"] }
Expand Down
9 changes: 5 additions & 4 deletions core/tests/transport_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ where
}
}

#[test]
fn upgrade_pipeline() {
#[tokio::test]
async fn upgrade_pipeline() {
let listener_keys = identity::Keypair::generate_ed25519();
let listener_id = listener_keys.public().to_peer_id();
let mut listener_transport = MemoryTransport::default()
Expand Down Expand Up @@ -137,6 +137,7 @@ fn upgrade_pipeline() {
assert_eq!(peer, listener_id);
};

async_std::task::spawn(server);
async_std::task::block_on(client);
tokio::spawn(server);

client.await;
}
2 changes: 1 addition & 1 deletion misc/allow-block-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ libp2p-swarm = { workspace = true }
libp2p-identity = { workspace = true, features = ["peerid"] }

[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }
tokio = { workspace = true, features = ["rt", "macros"] }
libp2p-swarm-derive = { path = "../../swarm-derive" }
libp2p-swarm-test = { path = "../../swarm-test" }

Expand Down
18 changes: 9 additions & 9 deletions misc/allow-block-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ mod tests {

use super::*;

#[async_std::test]
#[tokio::test]
async fn cannot_dial_blocked_peer() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
Expand All @@ -319,7 +319,7 @@ mod tests {
assert!(cause.downcast::<Blocked>().is_ok());
}

#[async_std::test]
#[tokio::test]
async fn can_dial_unblocked_peer() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
Expand All @@ -333,15 +333,15 @@ mod tests {
dial(&mut dialer, &listener).unwrap();
}

#[async_std::test]
#[tokio::test]
async fn blocked_peer_cannot_dial_us() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
listener.listen().with_memory_addr_external().await;

listener.behaviour_mut().block_peer(*dialer.local_peer_id());
dial(&mut dialer, &listener).unwrap();
async_std::task::spawn(dialer.loop_on_next());
tokio::spawn(dialer.loop_on_next());

let cause = listener
.wait(|e| match e {
Expand All @@ -355,7 +355,7 @@ mod tests {
assert!(cause.downcast::<Blocked>().is_ok());
}

#[async_std::test]
#[tokio::test]
async fn connections_get_closed_upon_blocked() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
Expand All @@ -381,7 +381,7 @@ mod tests {
assert_eq!(closed_listener_peer, *dialer.local_peer_id());
}

#[async_std::test]
#[tokio::test]
async fn cannot_dial_peer_unless_allowed() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
Expand All @@ -396,7 +396,7 @@ mod tests {
assert!(dial(&mut dialer, &listener).is_ok());
}

#[async_std::test]
#[tokio::test]
async fn cannot_dial_disallowed_peer() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
Expand All @@ -413,7 +413,7 @@ mod tests {
assert!(cause.downcast::<NotAllowed>().is_ok());
}

#[async_std::test]
#[tokio::test]
async fn not_allowed_peer_cannot_dial_us() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
Expand Down Expand Up @@ -450,7 +450,7 @@ mod tests {
assert!(incoming_cause.downcast::<NotAllowed>().is_ok());
}

#[async_std::test]
#[tokio::test]
async fn connections_get_closed_upon_disallow() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
Expand Down
2 changes: 1 addition & 1 deletion misc/connection-limits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ libp2p-swarm = { workspace = true }
libp2p-identity = { workspace = true, features = ["peerid"] }

[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }
tokio = { workspace = true, features = ["rt-multi-thread"] }
libp2p-identify = { workspace = true }
libp2p-ping = { workspace = true }
libp2p-swarm-derive = { path = "../../swarm-derive" }
Expand Down
11 changes: 7 additions & 4 deletions misc/connection-limits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ mod tests {
};
use libp2p_swarm_test::SwarmExt;
use quickcheck::*;
use tokio::runtime::Runtime;

use super::*;

Expand Down Expand Up @@ -452,7 +453,8 @@ mod tests {
)
});

async_std::task::block_on(async {
let rt = Runtime::new().unwrap();
rt.block_on(async {
dariusc93 marked this conversation as resolved.
Show resolved Hide resolved
let (listen_addr, _) = swarm1.listen().with_memory_addr_external().await;

for _ in 0..limit {
Expand All @@ -461,7 +463,7 @@ mod tests {

swarm2.dial(listen_addr).unwrap();

async_std::task::spawn(swarm2.loop_on_next());
tokio::spawn(swarm2.loop_on_next());

let cause = swarm1
.wait(|event| match event {
Expand Down Expand Up @@ -503,11 +505,12 @@ mod tests {
});
let mut swarm2 = Swarm::new_ephemeral(|_| Behaviour::new(ConnectionLimits::default()));

async_std::task::block_on(async {
let rt = Runtime::new().unwrap();
rt.block_on(async {
dariusc93 marked this conversation as resolved.
Show resolved Hide resolved
// Have swarm2 dial swarm1.
let (listen_addr, _) = swarm1.listen().await;
swarm2.dial(listen_addr).unwrap();
async_std::task::spawn(swarm2.loop_on_next());
tokio::spawn(swarm2.loop_on_next());

// Wait for the ConnectionDenier of swarm1 to deny the established connection.
let cause = swarm1
Expand Down
Loading