Skip to content

Commit

Permalink
Resolve Turbo Stream test flakiness
Browse files Browse the repository at this point in the history
Replace looping mechanisms with Capybara assertion for the presence of a
`<turbo-cable-stream-source>` element.
  • Loading branch information
seanpdoyle committed Nov 19, 2022
1 parent 4868855 commit 2e38b70
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions test/system/broadcasts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def subscribe_to_broadcasts

assert_no_button "Start listening for broadcasts"

Timeout.timeout(Capybara.default_max_wait_time) { wait_for_subscriber }
assert_selector :element, "turbo-cable-stream-source", visible: false
end

def assert_broadcasts_text(text, to:, &block)
Expand All @@ -53,18 +53,4 @@ def assert_broadcasts_text(text, to:, &block)

within(:element, id: to) { assert_text text }
end

def wait_for_subscriber
loop do
subscriber_map = ActionCable.server.pubsub.instance_variable_get(:@subscriber_map)
if subscriber_map.is_a?(ActionCable::SubscriptionAdapter::SubscriberMap)
subscribers = subscriber_map.instance_variable_get(:@subscribers)
sync = subscriber_map.instance_variable_get(:@sync)
sync.synchronize do
return unless subscribers.empty?
end
end
sleep 0.1
end
end
end

0 comments on commit 2e38b70

Please sign in to comment.