Skip to content

Add tests for SSE log context propagation across fiber boundaries#267

Merged
rsamoilov merged 1 commit intorage-rb:mainfrom
jsxs0:add-sse-context-propagation-specs
Apr 9, 2026
Merged

Add tests for SSE log context propagation across fiber boundaries#267
rsamoilov merged 1 commit intorage-rb:mainfrom
jsxs0:add-sse-context-propagation-specs

Conversation

@jsxs0
Copy link
Copy Markdown
Contributor

@jsxs0 jsxs0 commented Apr 8, 2026

Summary

Add tests for the log context capture/restore cycle in SSE::Application, where parent fiber log tags are saved during initialization and restored in the child fiber spawned by start_stream.

Context

While working on the SSE specs for #248 and #264, I noticed that every aspect of SSE::Application now has dedicated test coverage: graceful shutdown (#261), connection cleanup for raw streams (#248), single-value streams (#264). But the context propagation itself had none.

The capture happens at initialization:

@log_tags, @log_context = Fiber[:__rage_logger_tags], Fiber[:__rage_logger_context]

The restore happens in the streaming fiber:

Fiber.schedule do
  Fiber[:__rage_logger_tags], Fiber[:__rage_logger_context] = @log_tags, @log_context

This is the mechanism that ensures log correlation survives the fiber boundary. Without it, a streaming response loses its request ID and any custom log context.

Test plan

4 tests covering:

  • Capture from parent fiber on initialization

  • Restore in child fiber for enumerator streams

  • Restore in child fiber for proc streams

  • Nil context handled gracefully

    bundle exec rspec spec/sse/ -- 57 examples, 0 failures

@jsxs0 jsxs0 force-pushed the add-sse-context-propagation-specs branch 4 times, most recently from 360b225 to 5b473ae Compare April 8, 2026 06:53
@jsxs0 jsxs0 force-pushed the add-sse-context-propagation-specs branch from 5b473ae to ce1d824 Compare April 8, 2026 06:55
Copy link
Copy Markdown
Member

@rsamoilov rsamoilov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@rsamoilov rsamoilov merged commit e25b9cf into rage-rb:main Apr 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants