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

muxers: Add test harness for StreamMuxer implementations #2952

Merged
merged 17 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ members = [
"misc/quickcheck-ext",
"muxers/mplex",
"muxers/yamux",
"muxers/test-harness",
"protocols/dcutr",
"protocols/autonat",
"protocols/floodsub",
Expand Down
3 changes: 3 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
- Remove default features. If you previously depended on `secp256k1` or `ecdsa` you need to enable these explicitly
now. See [PR 2918].

- Deprecate `StreamMuxerExt::next_{inbound,outbound}`. See [PR XXXX].

[PR 2915]: https://github.com/libp2p/rust-libp2p/pull/2915
[PR 2918]: https://github.com/libp2p/rust-libp2p/pull/2918
[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX

# 0.36.0

Expand Down
8 changes: 8 additions & 0 deletions core/src/muxing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,19 @@ pub trait StreamMuxerExt: StreamMuxer + Sized {
}

/// Returns a future that resolves to the next inbound `Substream` opened by the remote.
#[deprecated(
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
since = "0.36.1",
note = "This future violates the `StreamMuxer` contract because it doesn't call `StreamMuxer::poll`."
)]
fn next_inbound(&mut self) -> NextInbound<'_, Self> {
NextInbound(self)
}

/// Returns a future that opens a new outbound `Substream` with the remote.
#[deprecated(
since = "0.36.1",
note = "This future violates the `StreamMuxer` contract because it doesn't call `StreamMuxer::poll`."
)]
fn next_outbound(&mut self) -> NextOutbound<'_, Self> {
NextOutbound(self)
}
Expand Down
3 changes: 2 additions & 1 deletion muxers/mplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ smallvec = "1.6.1"
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }

[dev-dependencies]
async-std = "1.7.0"
async-std = { version = "1.7.0", features = ["attributes"] }
criterion = "0.4"
env_logger = "0.9"
futures = "0.3"
libp2p = { path = "../..", features = ["full"] }
libp2p-muxer-test-harness = { path = "../test-harness" }
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }

[[bench]]
Expand Down
8 changes: 6 additions & 2 deletions muxers/mplex/benches/split_send_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ fn run(
}
transport::TransportEvent::Incoming { upgrade, .. } => {
let (_peer, mut conn) = upgrade.await.unwrap();
let mut s = conn.next_inbound().await.expect("unexpected error");
// Just calling `poll_inbound` without `poll` is fine here because mplex makes progress through all `poll_` functions. It is hacky though.
let mut s = poll_fn(|cx| conn.poll_inbound_unpin(cx))
.await
.expect("unexpected error");

let mut buf = vec![0u8; payload_len];
let mut off = 0;
Expand All @@ -139,7 +142,8 @@ fn run(
let sender = async move {
let addr = addr_receiver.await.unwrap();
let (_peer, mut conn) = sender_trans.dial(addr).unwrap().await.unwrap();
let mut stream = conn.next_outbound().await.unwrap();
// Just calling `poll_outbound` without `poll` is fine here because mplex makes progress through all `poll_` functions. It is hacky though.
let mut stream = poll_fn(|cx| conn.poll_outbound_unpin(cx)).await.unwrap();
let mut off = 0;
loop {
let n = poll_fn(|cx| Pin::new(&mut stream).poll_write(cx, &payload[off..]))
Expand Down
84 changes: 0 additions & 84 deletions muxers/mplex/tests/async_write.rs

This file was deleted.

37 changes: 37 additions & 0 deletions muxers/mplex/tests/compliance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use libp2p_mplex::MplexConfig;

#[async_std::test]
async fn close_implies_flush() {
let (alice, bob) =
libp2p_muxer_test_harness::connected_muxers_on_memory_transport::<MplexConfig, _, _>()
.await;

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

#[async_std::test]
async fn dialer_can_receive() {
let (alice, bob) =
libp2p_muxer_test_harness::connected_muxers_on_memory_transport::<MplexConfig, _, _>()
.await;

libp2p_muxer_test_harness::dialer_can_receive(alice, bob).await;
}

#[async_std::test]
async fn read_after_close() {
let (alice, bob) =
libp2p_muxer_test_harness::connected_muxers_on_memory_transport::<MplexConfig, _, _>()
.await;

libp2p_muxer_test_harness::read_after_close(alice, bob).await;
}

#[async_std::test]
async fn write_to_remote_closed() {
let (alice, bob) =
libp2p_muxer_test_harness::connected_muxers_on_memory_transport::<MplexConfig, _, _>()
.await;

libp2p_muxer_test_harness::write_to_remote_closed(alice, bob).await;
}
198 changes: 0 additions & 198 deletions muxers/mplex/tests/two_peers.rs

This file was deleted.

Loading