Merge pull request #41609

This commit is contained in:
Rafael Mendonça França 2021-06-23 18:29:49 +00:00
commit 3a98e7da62
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
4 changed files with 34 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* Fix ActionController::Live controller test deadlocks by removing the body buffer size limit for tests.
*Dylan Thacker-Smith*
* New `ActionController::ConditionalGet#no_store` method to set HTTP cache control `no-store` directive.
*Tadas Sasnauskas*

View File

@ -127,6 +127,11 @@ module ActionController
class Buffer < ActionDispatch::Response::Buffer #:nodoc:
include MonitorMixin
class << self
attr_accessor :queue_size
end
@queue_size = 10
# Ignore that the client has disconnected.
#
# If this value is `true`, calling `write` after the client
@ -136,7 +141,7 @@ module ActionController
attr_accessor :ignore_disconnect
def initialize(response)
super(response, SizedQueue.new(10))
super(response, build_queue(self.class.queue_size))
@error_callback = lambda { true }
@cv = new_cond
@aborted = false
@ -219,6 +224,10 @@ module ActionController
yield str
end
end
def build_queue(queue_size)
queue_size ? SizedQueue.new(queue_size) : Queue.new
end
end
class Response < ActionDispatch::Response #:nodoc: all

View File

@ -24,6 +24,9 @@ module ActionController
def new_controller_thread # :nodoc:
yield
end
# Avoid a deadlock from the queue filling up
Buffer.queue_size = nil
end
# ActionController::TestCase will be deprecated and moved to a gem in the future.

View File

@ -264,6 +264,13 @@ module ActionController
end
end
def overfill_default_buffer
("a".."z").each do |char|
response.stream.write(char)
end
response.stream.close
end
def ignore_client_disconnect
response.stream.ignore_disconnect = true
@ -368,7 +375,15 @@ module ActionController
assert t.join(3), "timeout expired before the thread terminated"
end
def test_infinite_test_buffer
get :overfill_default_buffer
assert_equal ("a".."z").to_a.join, response.stream.body
end
def test_abort_with_full_buffer
old_queue_size = ActionController::Live::Buffer.queue_size
ActionController::Live::Buffer.queue_size = 10
@controller.latch = Concurrent::CountDownLatch.new
@controller.error_latch = Concurrent::CountDownLatch.new
@ -389,6 +404,8 @@ module ActionController
@controller.error_latch.wait
assert_match "Error while streaming", output.rewind && output.read
end
ensure
ActionController::Live::Buffer.queue_size = old_queue_size
end
def test_ignore_client_disconnect