Fixing flaky system tests when a job broadcasts multiple Turbo Stream updates

@gpassero Gary
Fri, 20 Mar 2026 14:27:26 +0000

There’s a class of Turbo Stream system test flakiness that connect_turbo_cable_stream_sources doesn’t fix — when the issue isn’t the WebSocket connection timing, but the ActionCable thread pool not flushing before your Capybara assertion runs.

There are actually 2 spots in the ActionCable broadcast call chain that introduce non-determinism in a test environment, in ActionCable::Channel::Streams#worker_pool_stream_handler and ActionCable::SubscriptionAdapter::Async::AsyncSubscriberMap

We wrote up the full diagnosis and a fix (making worker_pool_stream_handler call invoke synchronously) here:

DEV Community

Fixing a stubborn class of flaky Turbo Stream system tests

If you've written system tests against a Rails app that uses Turbo Streams, you've probably hit this:...

The drop-in spec support file is at: Monkey-patch Rails ActionCable for deterministic behavior in tests · GitHub

Happy to discuss — curious whether others have hit this or found different approaches.