diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-14 11:06:20 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-14 11:06:20 -0700 |
commit | 468a55b741f2ceacd8a988a9487db6d767ca8616 (patch) | |
tree | cbf935eda9855db7f9d568b599f7c63246a29399 /actionpack | |
parent | 7645a5f85d7fc88b5f05f7fe4b73b743078bb069 (diff) | |
parent | 284a9ba8ecbbaac598179af6fc65aed7bcf5785b (diff) | |
download | rails-468a55b741f2ceacd8a988a9487db6d767ca8616.tar.gz rails-468a55b741f2ceacd8a988a9487db6d767ca8616.tar.bz2 rails-468a55b741f2ceacd8a988a9487db6d767ca8616.zip |
Merge pull request #20866 from jdantonio/countdown-latch
Replace `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch` from concurrent-ruby.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 5 | ||||
-rw-r--r-- | actionpack/actionpack.gemspec | 1 | ||||
-rw-r--r-- | actionpack/test/controller/live_stream_test.rb | 28 | ||||
-rw-r--r-- | actionpack/test/dispatch/live_response_test.rb | 14 |
4 files changed, 27 insertions, 21 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 46856ffc5d..6c6f27ce90 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,8 @@ +* Replaced `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch` + from the concurrent-ruby gem. + + *Jerry D'Antonio* + * Add ability to filter parameters based on parent keys. # matches {credit_card: {code: "xxxx"}} diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec index 1bba9df969..7830242af5 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |s| s.add_dependency 'rails-html-sanitizer', '~> 1.0', '>= 1.0.2' s.add_dependency 'rails-dom-testing', '~> 1.0', '>= 1.0.5' s.add_dependency 'actionview', version + s.add_dependency 'concurrent-ruby', '~> 0.9.0' s.add_development_dependency 'activemodel', version end diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb index 0c65270ec1..6161e3f47a 100644 --- a/actionpack/test/controller/live_stream_test.rb +++ b/actionpack/test/controller/live_stream_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/concurrency/latch' +require 'concurrent/atomics' Thread.abort_on_exception = true module ActionController @@ -145,7 +145,7 @@ module ActionController response.headers['Content-Type'] = 'text/event-stream' %w{ hello world }.each do |word| response.stream.write word - latch.await + latch.wait end response.stream.close end @@ -212,7 +212,7 @@ module ActionController # .. plus one more, because the #each frees up a slot: response.stream.write '.' - latch.release + latch.count_down # This write will block, and eventually raise response.stream.write 'x' @@ -233,7 +233,7 @@ module ActionController end logger.info 'Work complete' - latch.release + latch.count_down end end @@ -278,7 +278,7 @@ module ActionController def test_async_stream rubinius_skip "https://github.com/rubinius/rubinius/issues/2934" - @controller.latch = ActiveSupport::Concurrency::Latch.new + @controller.latch = Concurrent::CountDownLatch.new parts = ['hello', 'world'] @controller.request = @request @@ -289,8 +289,8 @@ module ActionController resp.stream.each do |part| assert_equal parts.shift, part ol = @controller.latch - @controller.latch = ActiveSupport::Concurrency::Latch.new - ol.release + @controller.latch = Concurrent::CountDownLatch.new + ol.count_down end } @@ -300,23 +300,23 @@ module ActionController end def test_abort_with_full_buffer - @controller.latch = ActiveSupport::Concurrency::Latch.new + @controller.latch = Concurrent::CountDownLatch.new @request.parameters[:format] = 'plain' @controller.request = @request @controller.response = @response - got_error = ActiveSupport::Concurrency::Latch.new + got_error = Concurrent::CountDownLatch.new @response.stream.on_error do ActionController::Base.logger.warn 'Error while streaming' - got_error.release + got_error.count_down end t = Thread.new(@response) { |resp| resp.await_commit _, _, body = resp.to_a body.each do |part| - @controller.latch.await + @controller.latch.wait body.close break end @@ -325,13 +325,13 @@ module ActionController capture_log_output do |output| @controller.process :overfill_buffer_and_die t.join - got_error.await + got_error.wait assert_match 'Error while streaming', output.rewind && output.read end end def test_ignore_client_disconnect - @controller.latch = ActiveSupport::Concurrency::Latch.new + @controller.latch = Concurrent::CountDownLatch.new @controller.request = @request @controller.response = @response @@ -349,7 +349,7 @@ module ActionController @controller.process :ignore_client_disconnect t.join Timeout.timeout(3) do - @controller.latch.await + @controller.latch.wait end assert_match 'Work complete', output.rewind && output.read end diff --git a/actionpack/test/dispatch/live_response_test.rb b/actionpack/test/dispatch/live_response_test.rb index 512f3a8a7a..5cfa5f7b3b 100644 --- a/actionpack/test/dispatch/live_response_test.rb +++ b/actionpack/test/dispatch/live_response_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/concurrency/latch' +require 'concurrent/atomics' module ActionController module Live @@ -27,18 +27,18 @@ module ActionController end def test_parallel - latch = ActiveSupport::Concurrency::Latch.new + latch = Concurrent::CountDownLatch.new t = Thread.new { @response.stream.write 'foo' - latch.await + latch.wait @response.stream.close } @response.await_commit @response.each do |part| assert_equal 'foo', part - latch.release + latch.count_down end assert t.join end @@ -62,15 +62,15 @@ module ActionController def test_headers_cannot_be_written_after_webserver_reads @response.stream.write 'omg' - latch = ActiveSupport::Concurrency::Latch.new + latch = Concurrent::CountDownLatch.new t = Thread.new { @response.stream.each do |chunk| - latch.release + latch.count_down end } - latch.await + latch.wait assert @response.headers.frozen? e = assert_raises(ActionDispatch::IllegalStateError) do @response.headers['Content-Length'] = "zomg" |