Skip to content

Commit

Permalink
chore: use tokio instead of async-std
Browse files Browse the repository at this point in the history
ref #4449

Pull-Request: #5828.
  • Loading branch information
kamuik16 authored Jan 29, 2025
1 parent 5ac2e20 commit c625951
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 52 deletions.
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 = ["macros", "rt-multi-thread"] }
libp2p-identify = { workspace = true }
libp2p-ping = { workspace = true }
libp2p-swarm-derive = { path = "../../swarm-derive" }
Expand Down
66 changes: 33 additions & 33 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 {
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 @@ -496,42 +498,40 @@ mod tests {
/// in [`SwarmEvent::ConnectionEstablished`] as the connection might still be denied by a
/// sibling [`NetworkBehaviour`] in the former case. Only in the latter case
/// ([`SwarmEvent::ConnectionEstablished`]) can the connection be seen as established.
#[test]
fn support_other_behaviour_denying_connection() {
#[tokio::test]
async fn support_other_behaviour_denying_connection() {
let mut swarm1 = Swarm::new_ephemeral(|_| {
Behaviour::new_with_connection_denier(ConnectionLimits::default())
});
let mut swarm2 = Swarm::new_ephemeral(|_| Behaviour::new(ConnectionLimits::default()));

async_std::task::block_on(async {
// Have swarm2 dial swarm1.
let (listen_addr, _) = swarm1.listen().await;
swarm2.dial(listen_addr).unwrap();
async_std::task::spawn(swarm2.loop_on_next());

// Wait for the ConnectionDenier of swarm1 to deny the established connection.
let cause = swarm1
.wait(|event| match event {
SwarmEvent::IncomingConnectionError {
error: ListenError::Denied { cause },
..
} => Some(cause),
_ => None,
})
.await;

cause.downcast::<std::io::Error>().unwrap();

assert_eq!(
0,
swarm1
.behaviour_mut()
.limits
.established_inbound_connections
.len(),
"swarm1 connection limit behaviour to not count denied established connection as established connection"
)
});
// Have swarm2 dial swarm1.
let (listen_addr, _) = swarm1.listen().await;
swarm2.dial(listen_addr).unwrap();
tokio::spawn(swarm2.loop_on_next());

// Wait for the ConnectionDenier of swarm1 to deny the established connection.
let cause = swarm1
.wait(|event| match event {
SwarmEvent::IncomingConnectionError {
error: ListenError::Denied { cause },
..
} => Some(cause),
_ => None,
})
.await;

cause.downcast::<std::io::Error>().unwrap();

assert_eq!(
0,
swarm1
.behaviour_mut()
.limits
.established_inbound_connections
.len(),
"swarm1 connection limit behaviour to not count denied established connection as established connection"
)
}

#[derive(libp2p_swarm_derive::NetworkBehaviour)]
Expand Down

0 comments on commit c625951

Please sign in to comment.