File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change
1
+ * Fix ActionController::Live controller test deadlocks by removing the body buffer size limit for tests.
2
+
3
+ * Dylan Thacker-Smith*
4
+
1
5
* New ` ActionController::ConditionalGet#no_store ` method to set HTTP cache control ` no-store ` directive.
2
6
3
7
* Tadas Sasnauskas*
Original file line number Diff line number Diff line change @@ -127,6 +127,11 @@ class ClientDisconnected < RuntimeError
127
127
class Buffer < ActionDispatch ::Response ::Buffer #:nodoc:
128
128
include MonitorMixin
129
129
130
+ class << self
131
+ attr_accessor :queue_size
132
+ end
133
+ @queue_size = 10
134
+
130
135
# Ignore that the client has disconnected.
131
136
#
132
137
# If this value is `true`, calling `write` after the client
@@ -136,7 +141,7 @@ class Buffer < ActionDispatch::Response::Buffer #:nodoc:
136
141
attr_accessor :ignore_disconnect
137
142
138
143
def initialize ( response )
139
- super ( response , SizedQueue . new ( 10 ) )
144
+ super ( response , build_queue ( self . class . queue_size ) )
140
145
@error_callback = lambda { true }
141
146
@cv = new_cond
142
147
@aborted = false
@@ -219,6 +224,10 @@ def each_chunk(&block)
219
224
yield str
220
225
end
221
226
end
227
+
228
+ def build_queue ( queue_size )
229
+ queue_size ? SizedQueue . new ( queue_size ) : Queue . new
230
+ end
222
231
end
223
232
224
233
class Response < ActionDispatch ::Response #:nodoc: all
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ module Live
24
24
def new_controller_thread # :nodoc:
25
25
yield
26
26
end
27
+
28
+ # Avoid a deadlock from the queue filling up
29
+ Buffer . queue_size = nil
27
30
end
28
31
29
32
# ActionController::TestCase will be deprecated and moved to a gem in the future.
Original file line number Diff line number Diff line change @@ -264,6 +264,13 @@ def overfill_buffer_and_die
264
264
end
265
265
end
266
266
267
+ def overfill_default_buffer
268
+ ( "a" .."z" ) . each do |char |
269
+ response . stream . write ( char )
270
+ end
271
+ response . stream . close
272
+ end
273
+
267
274
def ignore_client_disconnect
268
275
response . stream . ignore_disconnect = true
269
276
@@ -368,7 +375,15 @@ def test_async_stream
368
375
assert t . join ( 3 ) , "timeout expired before the thread terminated"
369
376
end
370
377
378
+ def test_infinite_test_buffer
379
+ get :overfill_default_buffer
380
+ assert_equal ( "a" .."z" ) . to_a . join , response . stream . body
381
+ end
382
+
371
383
def test_abort_with_full_buffer
384
+ old_queue_size = ActionController ::Live ::Buffer . queue_size
385
+ ActionController ::Live ::Buffer . queue_size = 10
386
+
372
387
@controller . latch = Concurrent ::CountDownLatch . new
373
388
@controller . error_latch = Concurrent ::CountDownLatch . new
374
389
@@ -389,6 +404,8 @@ def test_abort_with_full_buffer
389
404
@controller . error_latch . wait
390
405
assert_match "Error while streaming" , output . rewind && output . read
391
406
end
407
+ ensure
408
+ ActionController ::Live ::Buffer . queue_size = old_queue_size
392
409
end
393
410
394
411
def test_ignore_client_disconnect
You can’t perform that action at this time.
0 commit comments