-
Notifications
You must be signed in to change notification settings - Fork 0
Signal end of stream with terminator frame #314
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
leynos
merged 5 commits into
main
from
codex/implement-multi-packet-streaming-protocol-enhancement
Aug 15, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab109a7
Signal end of stream with terminator frame
leynos 63cb2d9
Format StreamEndWorld for rustfmt compliance
leynos 5abd37f
Clear response on protocol errors
leynos e1fdd0e
Clarify stream terminators and expand tests
leynos 6fc0b6c
Rename stream_end hook method
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
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,15 @@ | ||
| //! Test protocol that appends a terminator frame at end-of-stream. | ||
| //! | ||
| //! Used across integration and behavioural tests verifying the stream | ||
| //! termination mechanism. | ||
| use wireframe::hooks::{ConnectionContext, WireframeProtocol}; | ||
|
|
||
| /// Protocol that produces `0` as an explicit end-of-stream marker. | ||
| pub struct Terminator; | ||
|
|
||
| impl WireframeProtocol for Terminator { | ||
| type Frame = u8; | ||
| type ProtocolError = (); | ||
|
|
||
| fn stream_end_frame(&self, _ctx: &mut ConnectionContext) -> Option<Self::Frame> { Some(0) } | ||
| } |
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,4 @@ | ||
| Feature: Stream terminator frame | ||
| Scenario: Connection actor emits terminator after stream | ||
| When a streaming response completes | ||
| Then an end-of-stream frame is sent |
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 |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ | |
|
|
||
| mod correlation_steps; | ||
| mod panic_steps; | ||
| mod stream_end_steps; | ||
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,10 @@ | ||
| //! Steps for stream terminator behavioural tests. | ||
| use cucumber::{then, when}; | ||
|
|
||
| use crate::world::StreamEndWorld; | ||
|
|
||
| #[when("a streaming response completes")] | ||
| async fn when_stream(world: &mut StreamEndWorld) { world.process().await; } | ||
|
|
||
| #[then("an end-of-stream frame is sent")] | ||
| fn then_end(world: &mut StreamEndWorld) { world.verify(); } |
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,63 @@ | ||
| //! Tests for explicit end-of-stream signalling. | ||
| use std::sync::Arc; | ||
|
|
||
| use async_stream::try_stream; | ||
| use rstest::rstest; | ||
| use tokio_util::sync::CancellationToken; | ||
| use wireframe::{ | ||
| connection::ConnectionActor, | ||
| hooks::{ConnectionContext, ProtocolHooks, WireframeProtocol}, | ||
| push::PushQueues, | ||
| response::FrameStream, | ||
| }; | ||
|
|
||
| #[path = "common/terminator.rs"] | ||
| mod terminator; | ||
| use terminator::Terminator; | ||
|
|
||
| #[rstest] | ||
| #[tokio::test] | ||
| async fn emits_end_frame() { | ||
| let stream: FrameStream<u8> = Box::pin(try_stream! { | ||
| yield 1; | ||
| yield 2; | ||
| }); | ||
|
|
||
| let (queues, handle) = PushQueues::bounded(1, 1); | ||
| let shutdown = CancellationToken::new(); | ||
| let hooks = ProtocolHooks::from_protocol(&Arc::new(Terminator)); | ||
| let mut actor = ConnectionActor::with_hooks(queues, handle, Some(stream), shutdown, hooks); | ||
|
|
||
| let mut out = Vec::new(); | ||
| actor.run(&mut out).await.expect("actor run failed"); | ||
|
|
||
| assert_eq!(out, vec![1, 2, 0]); | ||
| } | ||
|
|
||
| #[rstest] | ||
| #[tokio::test] | ||
| async fn emits_no_end_frame_when_none() { | ||
| struct NoTerminator; | ||
|
|
||
| impl WireframeProtocol for NoTerminator { | ||
| type Frame = u8; | ||
| type ProtocolError = (); | ||
|
|
||
| fn stream_end_frame(&self, _ctx: &mut ConnectionContext) -> Option<Self::Frame> { None } | ||
| } | ||
|
|
||
| let stream: FrameStream<u8> = Box::pin(try_stream! { | ||
| yield 7; | ||
| yield 8; | ||
| }); | ||
|
|
||
| let (queues, handle) = PushQueues::bounded(1, 1); | ||
| let shutdown = CancellationToken::new(); | ||
| let hooks = ProtocolHooks::from_protocol(&Arc::new(NoTerminator)); | ||
| let mut actor = ConnectionActor::with_hooks(queues, handle, Some(stream), shutdown, hooks); | ||
|
|
||
| let mut out = Vec::new(); | ||
| actor.run(&mut out).await.expect("actor run failed"); | ||
|
|
||
| assert_eq!(out, vec![7, 8]); | ||
| } |
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
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.