Skip to content

Commit 7de4eb5

Browse files
committed
Avoid the test suite hanging when poping queue if it is empty
1 parent cb4f5eb commit 7de4eb5

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

test/lib/action_cable/subscription_adapter/solid_cable_test.rb

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
4242
subscribe_as_queue("channel") do |queue|
4343
@tx_adapter.broadcast("channel", "hello world")
4444

45-
assert_equal "hello world", queue.pop
45+
assert_equal "hello world", next_message_in_queue(queue)
4646
end
4747
end
4848

@@ -53,7 +53,7 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
5353

5454
@tx_adapter.broadcast("channel", "hello world")
5555

56-
assert_equal "hello world", queue.pop
56+
assert_equal "hello world", next_message_in_queue(queue)
5757
end
5858

5959
@tx_adapter.broadcast("channel", "hello void")
@@ -84,7 +84,7 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
8484
@tx_adapter.broadcast("channel", "apples")
8585

8686
received = []
87-
2.times { received << queue.pop }
87+
2.times { received << next_message_in_queue(queue) }
8888
assert_equal %w(apples bananas), received.sort
8989
end
9090
end
@@ -94,10 +94,10 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
9494
subscribe_as_queue("channel") do |queue_2|
9595
@tx_adapter.broadcast("channel", "hello")
9696

97-
assert_equal "hello", queue_2.pop
97+
assert_equal "hello", next_message_in_queue(queue_2)
9898
end
9999

100-
assert_equal "hello", queue.pop
100+
assert_equal "hello", next_message_in_queue(queue)
101101
end
102102
end
103103

@@ -107,8 +107,8 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
107107
@tx_adapter.broadcast("channel", "apples")
108108
@tx_adapter.broadcast("other channel", "oranges")
109109

110-
assert_equal "apples", queue.pop
111-
assert_equal "oranges", queue_2.pop
110+
assert_equal "apples", next_message_in_queue(queue)
111+
assert_equal "oranges", next_message_in_queue(queue_2)
112112
end
113113
end
114114
end
@@ -118,7 +118,7 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
118118
@tx_adapter.broadcast("other channel", "one")
119119
@tx_adapter.broadcast("channel", "two")
120120

121-
assert_equal "two", queue.pop
121+
assert_equal "two", next_message_in_queue(queue)
122122
end
123123
end
124124

@@ -130,8 +130,8 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
130130
@tx_adapter.broadcast(channel_1, "apples")
131131
@tx_adapter.broadcast(channel_2, "oranges")
132132

133-
assert_equal "apples", queue.pop
134-
assert_equal "oranges", queue_2.pop
133+
assert_equal "apples", next_message_in_queue(queue)
134+
assert_equal "oranges", next_message_in_queue(queue_2)
135135
end
136136
end
137137
end
@@ -142,7 +142,7 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
142142
subscribe_as_queue("channel") do |queue|
143143
@tx_adapter.broadcast("channel", "hello world")
144144

145-
assert_equal "hello world", queue.pop
145+
assert_equal "hello world", next_message_in_queue(queue)
146146
end
147147
end
148148
end
@@ -163,8 +163,8 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
163163
subscribe_as_queue("other") do |other_queue|
164164
assert_empty other_queue
165165
end
166-
assert_equal "channel3", queue.pop
167-
assert_equal "channel4", queue.pop
166+
assert_equal "channel3", next_message_in_queue(queue)
167+
assert_equal "channel4", next_message_in_queue(queue)
168168
end
169169

170170
@tx_adapter.broadcast("channel", "channel5")
@@ -206,4 +206,12 @@ def with_active_record_logger(logger)
206206
ensure
207207
ActiveRecord::Base.logger = old_logger
208208
end
209+
210+
def next_message_in_queue(queue)
211+
if queue.empty?
212+
raise "Queue is empty"
213+
else
214+
queue.pop
215+
end
216+
end
209217
end

0 commit comments

Comments
 (0)