-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
This is now covered by the compliance test suite.
This ensures we cover the same things as the original mplex tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very much in favor of this change. Thanks @thomaseizinger for the excellent design.
/// Verifies that the dialer of a substream can receive a message. | ||
pub async fn dialer_can_receive<A, B, S, E>(alice: A, bob: B) | ||
where | ||
A: StreamMuxer<Substream = S, Error = E> + Unpin, | ||
B: StreamMuxer<Substream = S, Error = E> + Unpin, | ||
S: AsyncRead + AsyncWrite + Send + Unpin + 'static, | ||
E: fmt::Debug, | ||
{ | ||
run_commutative( | ||
alice, | ||
bob, | ||
|mut stream| async move { | ||
let mut buf = Vec::new(); | ||
stream.read_to_end(&mut buf).await.unwrap(); | ||
|
||
assert_eq!(buf, b"PING"); | ||
}, | ||
|mut stream| async move { | ||
stream.write_all(b"PING").await.unwrap(); | ||
stream.close().await.unwrap(); | ||
}, | ||
) | ||
.await; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the official winner in the competition of most-concise-test-case within the rust-libp2p repository!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When it comes to tests, every character of noise counts. You don't want to read details that are not important :)
I'd like to get rid of the trait bounds put I don't think it is possible.
} | ||
|
||
#[async_std::test] | ||
#[ignore] // Hangs forever, is this a harness bug? It passes if we try to write to the stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May it be the case that the Rust yamux implementation only announces the stream to the remote once it writes the first byte onto it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be yeah.
Because of multistream-select
, we will always write something but it is still a bit odd.
I managed to adapt the mplex implementation so I got the reset test case to pass. Going to work on yamux next. |
5a9f29e
to
c3147f8
Compare
We should probably extract that into a separate PR. It might break something and that will make bisecting easier. |
c3147f8
to
c7ae3e7
Compare
Given that both our muxers, We can then fix the muxer implementations in a separate PR! |
c7ae3e7
to
ef5464a
Compare
Removed the mplex changes as per comment above and chat with @mxinden out-of-band. This is ready for another review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, wonderful work! Thanks Thomas!
Merging because semver checks are a false-positive error. |
Description
This adds a basic test harness for stream muxers. It covers everything that was covered by the old mplex tests but additionally runs them also for yamux.
yamux doesn't pass one of them. I don't understand yet whether it is a harness bug or an actual bug in yamux. In any case, this is a strict improvement over what we currently have so I would like to not block this PR on that. The harness will be used to make progress on the WebRTC implementation. See melekes#9 (comment).
As part of writing this harness, I realised that
StreamMuxerExt::next_{inbound,outbound}
were a bad idea because they don't uphold theStreamMuxer
contract of callingStreamMuxer::poll
so I went ahead and deprecated them.cc @melekes
Links to any relevant issues
Open Questions
Open tasks
StreamMuxerExt
functions into separate PR: core/muxer: DeprecateStreamMuxerExt::next_{inbound,outbound}
#3002write_to_remote_closed
testAdd test for resetting stream on dropChange checklist