Skip to content

Commit 4d4833f

Browse files
muxers: Add test harness for StreamMuxer implementations (#2952)
1 parent 981d586 commit 4d4833f

File tree

9 files changed

+426
-305
lines changed

9 files changed

+426
-305
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ members = [
152152
"misc/quickcheck-ext",
153153
"muxers/mplex",
154154
"muxers/yamux",
155+
"muxers/test-harness",
155156
"protocols/dcutr",
156157
"protocols/autonat",
157158
"protocols/floodsub",

muxers/mplex/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ smallvec = "1.6.1"
2323
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
2424

2525
[dev-dependencies]
26-
async-std = "1.7.0"
26+
async-std = { version = "1.7.0", features = ["attributes"] }
2727
criterion = "0.4"
2828
env_logger = "0.9"
2929
futures = "0.3"
3030
libp2p = { path = "../..", features = ["full"] }
31+
libp2p-muxer-test-harness = { path = "../test-harness" }
3132
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
3233

3334
[[bench]]

muxers/mplex/tests/async_write.rs

Lines changed: 0 additions & 91 deletions
This file was deleted.

muxers/mplex/tests/compliance.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use libp2p_mplex::MplexConfig;
2+
3+
#[async_std::test]
4+
async fn close_implies_flush() {
5+
let (alice, bob) =
6+
libp2p_muxer_test_harness::connected_muxers_on_memory_transport::<MplexConfig, _, _>()
7+
.await;
8+
9+
libp2p_muxer_test_harness::close_implies_flush(alice, bob).await;
10+
}
11+
12+
#[async_std::test]
13+
async fn dialer_can_receive() {
14+
let (alice, bob) =
15+
libp2p_muxer_test_harness::connected_muxers_on_memory_transport::<MplexConfig, _, _>()
16+
.await;
17+
18+
libp2p_muxer_test_harness::dialer_can_receive(alice, bob).await;
19+
}
20+
21+
#[async_std::test]
22+
async fn read_after_close() {
23+
let (alice, bob) =
24+
libp2p_muxer_test_harness::connected_muxers_on_memory_transport::<MplexConfig, _, _>()
25+
.await;
26+
27+
libp2p_muxer_test_harness::read_after_close(alice, bob).await;
28+
}

muxers/mplex/tests/two_peers.rs

Lines changed: 0 additions & 213 deletions
This file was deleted.

muxers/test-harness/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "libp2p-muxer-test-harness"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
license = "MIT"
7+
8+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+
10+
[dependencies]
11+
libp2p-core = { path = "../../core" }
12+
futures = "0.3.24"
13+
log = "0.4"
14+
futures-timer = "3.0.2"

0 commit comments

Comments
 (0)