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(request-response): migrate tests from async-std to tokio #5857

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Cargo.lock

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

9 changes: 6 additions & 3 deletions protocols/request-response/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ categories = ["network-programming", "asynchronous"]

[dependencies]
async-trait = "0.1"
cbor4ii = { version = "0.3.2", features = ["serde1", "use_std"], optional = true }
cbor4ii = { version = "0.3.2", features = [
"serde1",
"use_std",
], optional = true }
Comment on lines +15 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we revert this and stick with the previous format?

futures = { workspace = true }
libp2p-core = { workspace = true }
libp2p-swarm = { workspace = true }
libp2p-identity = { workspace = true }
rand = "0.8"
serde = { version = "1.0", optional = true}
serde = { version = "1.0", optional = true }
serde_json = { version = "1.0.117", optional = true }
smallvec = "1.13.2"
tracing = { workspace = true }
Expand All @@ -30,7 +33,7 @@ cbor = ["dep:serde", "dep:cbor4ii", "libp2p-swarm/macros"]

[dev-dependencies]
anyhow = "1.0.86"
async-std = { version = "1.6.2", features = ["attributes"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
rand = "0.8"
libp2p-swarm-test = { path = "../../swarm-test" }
futures_ringbuf = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion protocols/request-response/src/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ mod tests {

use crate::{cbor::codec::Codec, Codec as _};

#[async_std::test]
#[tokio::test]
async fn test_codec() {
let expected_request = TestRequest {
payload: "test_payload".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion protocols/request-response/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod tests {

use crate::Codec;

#[async_std::test]
#[tokio::test]
async fn test_codec() {
let expected_request = TestRequest {
payload: "test_payload".to_string(),
Expand Down
16 changes: 8 additions & 8 deletions protocols/request-response/tests/error_reporting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{io, iter, pin::pin, time::Duration};

use anyhow::{bail, Result};
use async_std::task::sleep;
use async_trait::async_trait;
use futures::prelude::*;
use libp2p_identity::PeerId;
Expand All @@ -12,9 +11,10 @@ use libp2p_swarm_test::SwarmExt;
use request_response::{
Codec, InboundFailure, InboundRequestId, OutboundFailure, OutboundRequestId, ResponseChannel,
};
use tokio::time::sleep;
use tracing_subscriber::EnvFilter;

#[async_std::test]
#[tokio::test]
async fn report_outbound_failure_on_read_response() {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down Expand Up @@ -70,7 +70,7 @@ async fn report_outbound_failure_on_read_response() {
futures::future::select(server_task, client_task).await;
}

#[async_std::test]
#[tokio::test]
async fn report_outbound_failure_on_write_request() {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down Expand Up @@ -113,7 +113,7 @@ async fn report_outbound_failure_on_write_request() {
futures::future::select(server_task, client_task).await;
}

#[async_std::test]
#[tokio::test]
async fn report_outbound_timeout_on_read_response() {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down Expand Up @@ -160,7 +160,7 @@ async fn report_outbound_timeout_on_read_response() {
futures::future::select(server_task, client_task).await;
}

#[async_std::test]
#[tokio::test]
async fn report_outbound_failure_on_max_streams() {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down Expand Up @@ -212,7 +212,7 @@ async fn report_outbound_failure_on_max_streams() {
futures::future::select(swarm1_task, swarm2_task).await;
}

#[async_std::test]
#[tokio::test]
async fn report_inbound_failure_on_read_request() {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down Expand Up @@ -249,7 +249,7 @@ async fn report_inbound_failure_on_read_request() {
futures::future::select(server_task, client_task).await;
}

#[async_std::test]
#[tokio::test]
async fn report_inbound_failure_on_write_response() {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down Expand Up @@ -315,7 +315,7 @@ async fn report_inbound_failure_on_write_response() {
futures::future::select(server_task, client_task).await;
}

#[async_std::test]
#[tokio::test]
async fn report_inbound_timeout_on_write_response() {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down
4 changes: 2 additions & 2 deletions protocols/request-response/tests/peer_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use libp2p_swarm_test::SwarmExt;
use serde::{Deserialize, Serialize};
use tracing_subscriber::EnvFilter;

#[async_std::test]
#[tokio::test]
#[cfg(feature = "cbor")]
async fn dial_succeeds_after_adding_peers_address() {
let _ = tracing_subscriber::fmt()
Expand All @@ -34,7 +34,7 @@ async fn dial_succeeds_after_adding_peers_address() {

swarm.dial(peer_id2).unwrap();

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

let (connected_peer_id, connected_address) = swarm
.wait(|event| match event {
Expand Down
10 changes: 5 additions & 5 deletions protocols/request-response/tests/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use rand::Rng;
use serde::{Deserialize, Serialize};
use tracing_subscriber::EnvFilter;

#[async_std::test]
#[tokio::test]
#[cfg(feature = "cbor")]
async fn is_response_outbound() {
let _ = tracing_subscriber::fmt()
Expand Down Expand Up @@ -84,7 +84,7 @@ async fn is_response_outbound() {
}

/// Exercises a simple ping protocol.
#[async_std::test]
#[tokio::test]
#[cfg(feature = "cbor")]
async fn ping_protocol() {
let ping = Ping("ping".to_string().into_bytes());
Expand Down Expand Up @@ -176,11 +176,11 @@ async fn ping_protocol() {
}
};

async_std::task::spawn(Box::pin(peer1));
tokio::spawn(Box::pin(peer1));
peer2.await;
}

#[async_std::test]
#[tokio::test]
#[cfg(feature = "cbor")]
async fn emits_inbound_connection_closed_failure() {
let ping = Ping("ping".to_string().into_bytes());
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn emits_inbound_connection_closed_failure() {
/// early close as a protocol violation which results in the connection being closed.
/// If the substream were not properly closed when dropped, the sender would instead
/// run into a timeout waiting for the response.
#[async_std::test]
#[tokio::test]
#[cfg(feature = "cbor")]
async fn emits_inbound_connection_closed_if_channel_is_dropped() {
let ping = Ping("ping".to_string().into_bytes());
Expand Down
Loading