-
Notifications
You must be signed in to change notification settings - Fork 0
Extract shared MultiPacket test helper #352
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a89d2f9
Add MultiPacket test helper implementation
leynos d04de0a
Clarify MultiPacket helper and extend world buffer
leynos 725ad82
Remove redundant clear in test world
leynos 4016bdd
Parameterize multi-packet tests
leynos 99ec569
Reset buffer per drain and track collector caller
leynos 6b51272
Resolve rebase conflicts and align tests with into_stream and shared …
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //! Helpers for draining `Response::MultiPacket` values in tests. | ||
| //! | ||
| //! These utilities collect all frames from a [`Response::MultiPacket`] into a | ||
| //! `Vec`, enabling concise assertions in tests and Cucumber steps. | ||
|
|
||
| use wireframe::Response; | ||
|
|
||
| /// Collect all frames from a [`Response::MultiPacket`]. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust | ||
| /// use tokio::sync::mpsc; | ||
| /// use wireframe::Response; | ||
| /// use wireframe_testing::collect_multi_packet; | ||
| /// | ||
| /// # async fn demo() { | ||
| /// let (tx, rx) = mpsc::channel(4); | ||
| /// tx.send(1u8).await.expect("send"); | ||
| /// drop(tx); | ||
| /// let frames = collect_multi_packet(Response::MultiPacket(rx)).await; | ||
| /// assert_eq!(frames, vec![1]); | ||
| /// # } | ||
| /// ``` | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| /// | ||
| /// # Panics | ||
| /// Panics if `resp` is not [`Response::MultiPacket`]; the panic message names | ||
| /// the received variant and is attributed to the caller. | ||
| #[must_use] | ||
| #[track_caller] | ||
| #[allow(ungated_async_fn_track_caller)] // track_caller on async is unstable | ||
| pub async fn collect_multi_packet<F, E>(resp: Response<F, E>) -> Vec<F> { | ||
| match resp { | ||
| Response::MultiPacket(mut rx) => { | ||
| let mut frames = Vec::new(); | ||
| while let Some(frame) = rx.recv().await { | ||
| frames.push(frame); | ||
| } | ||
| frames | ||
| } | ||
| Response::Single(_) => panic!("collect_multi_packet received Response::Single"), | ||
| Response::Vec(_) => panic!("collect_multi_packet received Response::Vec"), | ||
| Response::Stream(_) => panic!("collect_multi_packet received Response::Stream"), | ||
| Response::Empty => panic!("collect_multi_packet received Response::Empty"), | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.