-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tokio: introduce io::Duplex #2661
Conversation
Compilation failures aside, I'm a big +1 for this change. I've written one of these before and they're super handy. One thing that could be useful (in the future) is exposing some mechanism to drop writes, pseudo-randomly or whatever. |
Not sure how fancy you want to get Sean, but feel free to borrow as much of https://github.com/davidbarsky/stuff/blob/7cf9aa9684da4e3fffc7cdb5556bb65fb7d29af5/src/sim_stream.rs#L1 as you'd like. |
Oh cool! |
(I do think the naming on your PR is better, however.) |
How does this relate to https://github.com/tokio-rs/tokio/blob/master/tokio-test/src/io.rs |
As an update, this should go in |
MemStream is complimentary to that. The existing mock is great for asserting that certain read/write actions happened, while MemStream-style APIs are really handy for testing interactions between a client and a server together, in memory. Without a MemStream-style API, people (including me and in linkerd2-proxy!) ended up using the OS' loopback interface and port 0 to grab an unused port. |
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.
I didn't make my way through the whole thing since I have to head out but super excited for this!!!
Another naming option is
|
My super old C# implementation of that was called Actually it was only a unidirectional stream, and I simply created 2 of those where it was required. You can use this to model a unidirectional OS pipe, or a unidrectional QUIC channel, etc. |
Update: renamed to I have no idea why CI is blowing up. The tests run locally for me, and if I make the changes it says in CI, it produces warnings locally. Wat? |
CI failure is rust-lang/rust#73592. I'd suggest to add |
ce321da
to
8a9896d
Compare
8a9896d
to
4c983b7
Compare
`duplex` returns a pair of connected `DuplexStream`s. `DuplexStream` is a bidirectional type that can be used to simulate IO, but over an in-process piece of memory.
4c983b7
to
0b1dd1e
Compare
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.
LGTM. Thanks.
DuplexStream
provides a bidirectional type that can be used to simulate IO, but over an in-process piece of memory.I've seen implementations of this rewritten over and over in codebases. They are frequently used in testing situations, where something like
tokio_test::io
wouldn't work (not trying to assert exact read and write calls, but just join a client and server in a single process).